//物资采购结算 添加 详情
<template>
    <!-- 集采汇总编辑页 -->
    <div class="e-form">
        <BillTop title="物资采购结算编辑" @cancel="handleClose"></BillTop>
        <!-- //详情 添加页面 ↓ -->
        <div class="tabs">
            <el-tabs
                tab-position="left"
                v-model="tabsName"
                @tab-click="onChangeTab"
            >
                <!-- 基本信息 -->
                <el-tab-pane
                    label="基本信息"
                    name="baseInfo"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="结算明细"
                    name="planDetail"
                    :disabled="clickTabFlag"
                ></el-tab-pane>

                <el-tab-pane
                    label="服务费用"
                    name="fwfy"
                    :disabled="clickTabFlag"
                ></el-tab-pane>

                <el-tab-pane
                    label="保证金"
                    name="bzj"
                    :disabled="clickTabFlag"
                ></el-tab-pane>

                <el-tab-pane
                    label="附件信息"
                    name="accessory"
                    :disabled="clickTabFlag"
                ></el-tab-pane>

                <el-tab-pane
                    label="审核历史"
                    name="auditHistory"
                    :disabled="clickTabFlag"
                ></el-tab-pane>

                <!-- <el-tab-pane
          label="审核历史"
          name="auditHistory"
          :disabled="clickTabFlag"
        ></el-tab-pane> -->
                <div>
                    <!-- 基本信息 -->
                    <div id="baseInfoCon" class="con">
                        <div class="e-form">
                            <div class="tabs">
                                <div class="tabs-title" id="baseInfo">
                                    基本信息
                                </div>
                                <div style="width: 100%" class="form">
                                    <el-form
                                        ref="rulesBase"
                                        :model="formData"
                                        label-width="150px"
                                        :rules="rulesBase"
                                        class="demo-ruleForm"
                                    >
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="结算编号："
                                                    prop="billNo"
                                                >
                                                    <span>{{
                                                        formData.billNo
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="单据机构："
                                                    prop="orgName"
                                                >
                                                    <span>{{
                                                        formData.orgName
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="业务类型："
                                                    prop="businessType"
                                                >
                                                    <el-select
                                                        v-model="
                                                            formData.businessType
                                                        "
                                                        placeholder="请选择"
                                                        @change="
                                                            businessTypeChange
                                                        "
                                                        v-if="!isRedSingle"
                                                    >
                                                        <el-option
                                                            v-for="(
                                                                item, index
                                                            ) in typeArr || []"
                                                            :key="index"
                                                            :label="item.name"
                                                            :value="item.id"
                                                        >
                                                        </el-option>
                                                    </el-select>
                                                    <span v-else>{{
                                                        businessType
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="源单编号："
                                                >
                                                    <span>
                                                        {{
                                                            formData.sourceBillNo
                                                        }}
                                                        <i
                                                            slot="suffix"
                                                            class="
                                                                el-input__icon
                                                                el-icon-document-copy
                                                            "
                                                            @click="
                                                                sourceBillNoClick
                                                            "
                                                            v-if="
                                                                formData.sourceBillNo
                                                            "
                                                        ></i>
                                                    </span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="结算单位："
                                                    prop="settlementUnitName"
                                                >
                                                    <el-input
                                                        readonly
                                                        v-model="
                                                            formData.settlementUnitName
                                                        "
                                                        v-if="!isRedSingle"
                                                    ></el-input>
                                                    <el-button
                                                        @click="xzjsmx"
                                                        v-if="!isRedSingle"
                                                        >选择结算明细</el-button
                                                    >

                                                    <span v-else>{{
                                                        formData.settlementUnitName
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="结算日期："
                                                    prop="settlementDate"
                                                >
                                                    <el-date-picker
                                                        v-model="
                                                            formData.settlementDate
                                                        "
                                                        type="date"
                                                        placeholder="选择日期"
                                                        value-format="yyyy-MM-dd"
                                                        :clearable="false"
                                                        v-if="!isRedSingle"
                                                    >
                                                    </el-date-picker>
                                                    <span v-else>{{
                                                        formData.settlementDate
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="结算金额(元)："
                                                    prop="amount"
                                                >
                                                    <span v-if="!isRedSingle">{{
                                                        jiesuanjine
                                                    }}</span>
                                                    <span v-else>{{
                                                        formData.amount
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <!-- 返回id、名字 -->
                                                <el-form-item
                                                    label="经办人员："
                                                    prop="acceptancePersonnelName"
                                                >
                                                    <el-input
                                                        readonly
                                                        v-model="
                                                            formData.acceptancePersonnelName
                                                        "
                                                        v-if="!isRedSingle"
                                                    >
                                                        <i
                                                            slot="suffix"
                                                            class="
                                                                el-input__icon
                                                                el-icon-document-copy
                                                            "
                                                            @click="xzry"
                                                        ></i>
                                                    </el-input>
                                                    <span v-else>{{
                                                        formData.acceptancePersonnelName
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="发票编号："
                                                    prop="invoiceNo"
                                                >
                                                    <el-input
                                                        v-model="
                                                            formData.invoiceNo
                                                        "
                                                        v-if="!isRedSingle"
                                                    ></el-input>
                                                    <span v-else>{{
                                                        formData.invoiceNo
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="服务费用(元)："
                                                    prop="freight"
                                                >
                                                    <span v-if="!isRedSingle">{{
                                                        yunshufuwufeiyong
                                                    }}</span>
                                                    <span v-else>{{
                                                        formData.freight
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>

                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="税率%："
                                                    prop="taxRate"
                                                >
                                                    <el-input
                                                        v-model="
                                                            formData.taxRate
                                                        "
                                                        @change="shuilvchang"
                                                        v-enter-float="{
                                                            set: formData,
                                                            key: 'taxRate'
                                                        }"
                                                        v-if="!isRedSingle"
                                                    ></el-input>
                                                    <span v-else>{{
                                                        formData.taxRate
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="税价合计："
                                                    prop="totalAmount"
                                                >
                                                    <span v-if="!isRedSingle">{{
                                                        shuijiaheji
                                                    }}</span>
                                                    <span v-else>{{
                                                        formData.totalAmount
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>

                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="税额："
                                                    prop="taxAmount"
                                                >
                                                    <!-- <span>{{formData.taxAmount}}</span> -->
                                                    <!-- <span>{{shuie}}</span>taxAmount -->
                                                    <el-input
                                                        v-model="
                                                            formData.taxAmount
                                                        "
                                                        @blur="shuiechang"
                                                        v-enter-float="{
                                                            set: formData,
                                                            key: 'taxAmount'
                                                        }"
                                                        v-if="!isRedSingle"
                                                    ></el-input>
                                                    <span v-else>{{
                                                        formData.taxAmount
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="税额差额："
                                                >
                                                    <!-- <el-input v-model="formData.taxDifference"></el-input> -->
                                                    <span v-if="!isRedSingle">{{taxDifferenceFun}}</span>
                                                    <span v-else>{{formData.taxDifference}}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>

                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="冲预付款金额(元)："
                                                    :prop="
                                                        isOffsetAdvancePayment
                                                            ? 'offsetAdvancePayment'
                                                            : 'offsetAdvancePayments'
                                                    "
                                                >
                                                    <el-checkbox
                                                        v-model="
                                                            isOffsetAdvancePayment
                                                        "
                                                        :disabled="isRedSingle || !isTotalPrice || !formData.unoffsetAdvancePayment"
                                                    ></el-checkbox>
                                                    <el-input
                                                        :disabled="
                                                            !isOffsetAdvancePayment
                                                        "
                                                        v-model="
                                                            formData.offsetAdvancePayment
                                                        "
                                                        v-enter-float="{
                                                            set: formData,
                                                            key: 'offsetAdvancePayment'
                                                        }"
                                                        @blur="
                                                            offsetAdvancePaymentBlur(
                                                                formData.offsetAdvancePayment
                                                            )
                                                        "
                                                        v-if="!isRedSingle && isTotalPrice && isOffsetAdvancePayment"
                                                    ></el-input>
                                                    <span
                                                        v-else
                                                        style="
                                                            margin-left: 10px;
                                                        "
                                                        >{{
                                                            formData.offsetAdvancePayment
                                                        }}</span
                                                    >
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="单据来源："
                                                    prop="billSource"
                                                >
                                                    <span>{{
                                                        formData.billSource == 1
                                                            ? '新增'
                                                            : '验结一体'
                                                    }}</span>
                                                    <!-- <el-input v-model="formData.billSource"></el-input> -->
                                                </el-form-item>
                                            </el-col>
                                        </el-row>

                                        <el-row>
                                            <el-col
                                                :span="12"
                                                v-show="
                                                    formData.businessType == '0'
                                                "
                                            >
                                                <el-form-item
                                                    label="冲个人借支："
                                                >
                                                    <el-checkbox
                                                        v-model="
                                                            isPersonalBorrowing
                                                        "
                                                        @change="
                                                            isPersonalBorrowingChange
                                                        "
                                                        :disabled="isRedSingle"
                                                    ></el-checkbox>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="验收编号："
                                                    v-if="
                                                        formData.billSource ===
                                                        2
                                                    "
                                                >
                                                    <span
                                                        style="
                                                            color: blue;
                                                            cursor: pointer;
                                                        "
                                                        @click="
                                                            acceptanceBillNoClick
                                                        "
                                                        >{{
                                                            formData.acceptanceBillNo
                                                        }}</span
                                                    >
                                                </el-form-item>
                                            </el-col>
                                        </el-row>

                                        <el-row>
                                            <el-col
                                                :span="12"
                                                v-if="
                                                    formData.businessType == '0'
                                                "
                                            >
                                                <el-form-item
                                                    label="冲个人借支金额(元)："
                                                    :prop="
                                                        isPersonalBorrowing
                                                            ? 'personalBorrowing'
                                                            : 'personalBorrowings'
                                                    "
                                                >
                                                    <el-input
                                                        :disabled="
                                                            !isPersonalBorrowing
                                                        "
                                                        v-model="
                                                            formData.personalBorrowing
                                                        "
                                                        v-if="!isRedSingle"
                                                        @blur="
                                                            personalBorrowingBlur
                                                        "
                                                    ></el-input>
                                                    <span v-else>{{
                                                        formData.personalBorrowing
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="终期结算">
                                                    <el-checkbox
                                                        v-model="isEndSettle"
                                                        :disabled="isRedSingle"
                                                        @change='isEndSettleChange'
                                                    ></el-checkbox>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col
                                                :span="12"
                                                v-if="
                                                    formData.businessType == '0'
                                                "
                                            >
                                                <el-form-item
                                                    label="冲销对象："
                                                    :prop="
                                                        isPersonalBorrowing
                                                            ? 'reversalObjectNumber'
                                                            : 'reversalObjectNumbers'
                                                    "
                                                >
                                                    <el-input
                                                        readonly
                                                        v-model="
                                                            formData.reversalObjectNumber
                                                        "
                                                        v-if="!isRedSingle"
                                                    ></el-input>
                                                    <el-button
                                                        :disabled="
                                                            !isPersonalBorrowing
                                                        "
                                                        @click="xzcxdx"
                                                        v-if="!isRedSingle"
                                                        >选择冲销对象</el-button
                                                    >
                                                    <span v-else>{{
                                                        formData.reversalObjectNumber
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="币种：">
                                                    <span>{{
                                                        formData.currency
                                                    }}</span>
                                                    <!-- <el-input v-model="formData.currency"></el-input> -->
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col
                                                :span="12"
                                                v-if="
                                                    formData.businessType == '0'
                                                "
                                            >
                                                <el-form-item
                                                    label="借支人员："
                                                    :prop="
                                                        isPersonalBorrowing
                                                            ? 'borrowerName'
                                                            : 'borrowerNames'
                                                    "
                                                >
                                                    <el-input
                                                        readonly
                                                        v-model="
                                                            formData.borrowerName
                                                        "
                                                        v-if="!isRedSingle"
                                                    ></el-input>
                                                    <el-button
                                                        :disabled="
                                                            !isPersonalBorrowing
                                                        "
                                                        @click="xzjzry"
                                                        v-if="!isRedSingle"
                                                        >选择借支人员</el-button
                                                    >
                                                    <span v-else>{{
                                                        formData.borrowerName
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="本位币："
                                                    prop="baseCurName"
                                                >
                                                    <span>{{
                                                        formData.baseCurName
                                                    }}</span>
                                                    <!-- <el-input v-model="formData.baseCurName"></el-input> -->
                                                </el-form-item>
                                            </el-col>
                                        </el-row>

                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="本位币汇率："
                                                    prop="baseCurRate"
                                                >
                                                    <!-- <span>{{formData.baseCurName}}</span> -->
                                                    <el-input
                                                        v-if="
                                                            isxianshi1 &&
                                                            !isRedSingle
                                                        "
                                                        v-model="
                                                            formData.baseCurRate
                                                        "
                                                        v-enter-float2="{
                                                            set: formData,
                                                            key: 'baseCurRate'
                                                        }"
                                                        @blur="baseCurRateBlur"
                                                    ></el-input>
                                                    <span v-else>{{
                                                        formData.baseCurRate
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="人民币汇率："
                                                    prop="rmbRate"
                                                >
                                                    <span>{{
                                                        formData.rmbRate
                                                    }}</span>
                                                    <!-- <el-input v-model="formData.rmbRate"></el-input> -->
                                                </el-form-item>
                                            </el-col>
                                        </el-row>

                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="传财务共享："
                                                >
                                                    {{
                                                        formData.easId
                                                            ? '已传'
                                                            : '未传'
                                                    }}
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="录入人：">
                                                    <span>{{
                                                        formData.founderName
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>

                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="备注：">
                                                    <el-input
                                                        type="textarea"
                                                        :rows="2"
                                                        resize="none"
                                                        placeholder="请输入内容"
                                                        v-model="
                                                            formData.remarks
                                                        "
                                                        maxlength="500"
                                                    ></el-input>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>

                                        <el-row>
                                            <!-- <el-col :span="12">
                                            <el-form-item label="状态：">
                                               <span>{{formData.state}}</span>
                                            </el-form-item>
                                        </el-col> -->

                                            <el-col :span="12">
                                                <el-form-item label="状态：">
                                                    <span>{{
                                                        state.find(
                                                            x =>
                                                                x.value ==
                                                                formData.state
                                                        ).label
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col
                                                :span="12"
                                                v-if="
                                                    formData.redBillState !== -1
                                                "
                                            >
                                                <el-form-item label="冲红单">
                                                    <span
                                                        :style="
                                                            redBillStateStyle
                                                        "
                                                        >{{
                                                            redBillStateFun
                                                        }}</span
                                                    >
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                    </el-form>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- 结算明细 -->
                    <div id="planDetailCon" class="con">
                        <div class="tabs-title" id="planDetail">结算明细</div>
                        <div class="e-table">
                            <div class="top" v-if="!isRedSingle">
                                <div class="left">
                                    <div>
                                        <el-button
                                            size="small"
                                            style="
                                                background: rgb(75, 178, 255);
                                                color: #fff;
                                            "
                                            @click="xzjsmx"
                                            >新增</el-button
                                        >
                                        <el-button
                                            size="small"
                                            type="danger"
                                            @click="shanchumx"
                                            >删除</el-button
                                        >
                                        <!-- <el-button @click="chakan11">
                              查看
                          </el-button> -->
                                    </div>
                                </div>
                            </div>
                            <el-table
                                ref="multipleTable1"
                                :header-cell-style="{ textAlign: 'center' }"
                                :cell-style="{ textAlign: 'center' }"
                                :data.sync="wzlbTableData"
                                border
                                style="width: 100%"
                                :row-class-name="tableRowClassNameJS"
                                :cell-class-name="cellClsNm"
                                @selection-change="planTableSelect"
                                @select="selectRow"
                                @select-all="settlementSelectAll"
                                :tree-props="{
                                    children: 'children',
                                    hasChildren: 'hasChildren'
                                }"
                                default-expand-all
                                row-key="uuid"
                                :max-height="$store.state.tableHeight"
                                :class="tableHeadClass"
                                v-sortTable="{ 'tableData': wzlbTableData, '_this': this, 'ref': 'multipleTable1' }"
                            >
                                <el-table-column
                                    type="selection"
                                    width="55"
                                    v-if="!isRedSingle"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="materialClassName"
                                    label="物资类别"
                                    width="200"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="materialName"
                                    label="物资名称"
                                    width="150"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="spec"
                                    label="规格"
                                    width="110"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="texture"
                                    label="材质"
                                    width="110"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="unit"
                                    label="计量单位"
                                    width="100"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="warehouseName"
                                    label="仓库"
                                    width="150"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="acceptancePrice"
                                    label="验收单价"
                                    width="120"
                                >
                                </el-table-column>

                                <el-table-column
                                    prop="unsettledQuantity"
                                    label="未结算数量"
                                    width="110"
                                >
                                    <template v-slot="{ row }">
                                        <span v-if="!row.children">{{
                                            +(
                                                +row.unsettledQuantity -
                                                +row.settledQuantity
                                            ).toFixed(4)
                                        }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    label="结算数量"
                                    width="150"
                                    prop="settledQuantity"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-if="!row.children && !isRedSingle"
                                            v-model="row.settledQuantity"
                                            @blur="gaibian(row, '数量')"
                                            v-enter-float2="{
                                                set: row,
                                                key: 'settledQuantity'
                                            }"
                                        ></el-input>
                                        <span v-else>{{
                                            row.settledQuantity
                                        }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="acceptanceAmount"
                                    label="验收金额"
                                    width="130"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="settledPrice"
                                    label="结算单价(元)"
                                    width="130"
                                >
                                </el-table-column>
                                <!-- prop="amount" -->
                                <el-table-column
                                    label="结算金额(元)"
                                    width="130"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-if="!row.children && !isRedSingle"
                                            v-model="row.settledAmount"
                                            @blur="gaibian(row, '金额')"
                                            v-enter-float="{
                                                set: row,
                                                key: 'settledAmount'
                                            }"
                                        ></el-input>
                                        <span v-else>{{
                                            row.settledAmount
                                        }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="difference"
                                    label="差额"
                                    width="130"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="taxDifference"
                                    label="税额差额（元）"
                                    width="130"
                                >
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>

                    <!-- 服务费用 -->
                    <div id="fwfyCon" class="con">
                        <div class="tabs-title" id="fwfy">服务费用</div>
                        <div class="e-table" style="min-height: auto">
                            <div class="top" v-if="!isRedSingle">
                                <div class="left">
                                    <div>
                                        <el-button
                                            size="mini"
                                            class="btn-blue"
                                            @click="serviceFeeAdd"
                                            >新增行</el-button
                                        >
                                        <el-button
                                            size="mini"
                                            @click="shanchumx2"
                                            >删除</el-button
                                        >
                                    </div>
                                </div>
                            </div>
                            <!-- @cell-mouse-enter="cellMouseEnterF"
                                @cell-mouse-leave="cellMouseLeaveF"
                                 :row-class-name="tableRowClassNameF"
                                -->
                            <el-table
                                ref="multipleTable2"
                                :data="serviceFeeData"
                                border
                                style="width: 100%"
                                :cell-class-name="cellClsNm"
                                :row-class-name="tableRowClassName"
                                :header-cell-style="{ textAlign: 'center' }"
                                :cell-style="{ textAlign: 'center' }"
                                @selection-change="planTableSelect2"
                                :max-height="$store.state.tableHeight"
                                v-sortTable="{ 'tableData': serviceFeeData, '_this': this, 'ref': 'multipleTable2' }"
                            >
                                <el-table-column
                                    type="selection"
                                    width="55"
                                    v-if="!isRedSingle"
                                >
                                </el-table-column>
                                <el-table-column
                                    label="操作"
                                    fixed
                                    width="100px"
                                    align="left"
                                    v-if="!isRedSingle"
                                >
                                    <template v-slot="{ row, $index }">
                                        <!-- :class="{
                                                'icon-delete-active-color':
                                                    MouseEnterIdF == row.dtlId
                                            }" -->
                                        <i
                                            class="el-icon-delete"
                                            style="
                                                cursor: pointer;
                                                font-size: 20px;
                                                color: red;
                                            "
                                            @click="
                                                serviceFeeDelete(row, $index)
                                            "
                                        ></i>
                                    </template>
                                </el-table-column>
                                <el-table-column label="合同编号" width="200">
                                    <template v-slot="{ row, $index }">
                                        {{ row.contractBillNo }}
                                        <i
                                            style="
                                                cursor: pointer;
                                                font-size: 20px;
                                            "
                                            class="el-icon-document-copy"
                                            @click="contractDialog(row, $index)"
                                            v-if="!isRedSingle"
                                        ></i>
                                    </template>
                                </el-table-column>
                                <el-table-column label="结算单位" width="200">
                                    <template v-slot="{ row, $index }">
                                        {{ row.settlementUnitName }}
                                        <i
                                            style="
                                                cursor: pointer;
                                                font-size: 20px;
                                            "
                                            class="el-icon-document-copy"
                                            @click="
                                                billingUnitDialog(row, $index)
                                            "
                                            v-if="!isRedSingle"
                                        ></i>
                                    </template>
                                </el-table-column>
                                <el-table-column label="发票编号" width="200">
                                    <template v-slot="{ row }">
                                        <!-- v-if="
                                                basicFormData.redBillState !=
                                                '3'
                                            " -->
                                        <!-- @blur="invoiceNoBlur(row)" -->
                                        <el-input
                                            v-model="row.invoiceNo"
                                            v-enterInteger1
                                            placeholder=""
                                            v-if="!isRedSingle"
                                        ></el-input>
                                        <span v-else>{{ row.invoiceNo }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="清单名称" width="200">
                                    <template v-slot="{ row }">
                                        <!-- @blur="contractDtlNameBlur(row)" -->
                                        <el-input
                                            v-model="row.contractDtlName"
                                            placeholder=""
                                            v-if="!isRedSingle"
                                        ></el-input>
                                        <span v-else>{{
                                            row.contractDtlName
                                        }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="数量" width="150">
                                    <template v-slot="{ row }">
                                        <!-- @blur="quantityBlur(row)" -->
                                        <el-input
                                            v-model="row.quantity"
                                            v-enter-float2="{
                                                set: row,
                                                key: 'quantity'
                                            }"
                                            placeholder=""
                                            @input="danjia(row, '数量')"
                                            v-if="!isRedSingle"
                                        ></el-input>
                                        <span v-else>{{ row.quantity }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="price"
                                    label="单价(元)"
                                ></el-table-column>
                                <el-table-column label="金额(元)" width="150">
                                    <template v-slot="{ row }">
                                        <!-- @blur="amountBlur(row)" -->
                                        <el-input
                                            @input="danjia(row, '金额')"
                                            v-model="row.amount"
                                            v-enter-float="{
                                                set: row,
                                                key: 'amount'
                                            }"
                                            placeholder=""
                                            v-if="!isRedSingle"
                                        ></el-input>
                                        <span v-else>{{ row.amount }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="d"
                                    label="税率%"
                                    width="100"
                                >
                                    <template v-slot="{ row }">
                                        <!-- @blur="taxRateBlur(row)" -->
                                        <el-input
                                            @blur="shuieheji(row)"
                                            v-model="row.taxRate"
                                            v-enter-float="{
                                                set: row,
                                                key: 'taxRate'
                                            }"
                                            placeholder=""
                                            @input.native="onInput0_100"
                                            v-if="!isRedSingle"
                                        ></el-input>
                                        <span v-else>{{ row.amount }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="税额(元)" width="150">
                                    <template v-slot="{ row }">
                                            <el-input
                                            v-model="row.taxAmount"
                                            v-enter-float="{
                                                set: row,
                                                key: 'taxAmount'
                                            }"
                                            placeholder=""
                                            @blur="shuieheji(row)"
                                            v-if='!isRedSingle'
                                            ></el-input>
                                            <span v-else>{{ row.taxAmount }}</span>
                                        </template>
                                </el-table-column>
                                <el-table-column
                                    prop="totalAmount"
                                    label="税额合计(元)"
                                    width="150"
                                >
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>

                    <!-- 保证金 -->
                    <div id="bzjCon" class="con">
                        <div class="tabs-title" id="bzj">保证金</div>
                        <div class="lll">^ 暂扣保证金</div>
                        <div class="e-table" style="min-height: auto">
                            <div class="top" v-if="!isRedSingle">
                                <div class="left">
                                    <div>
                                        <el-button
                                            size="mini"
                                            class="btn-blue"
                                            @click="addzkbzj"
                                            >添加</el-button
                                        >
                                        <el-button
                                            size="mini"
                                            @click="shanchumx3"
                                            >删除</el-button
                                        >
                                    </div>
                                </div>
                            </div>
                            <!-- @cell-mouse-enter="cellMouseEnter"
                                @cell-mouse-leave="cellMouseLeave" -->
                            <el-table
                                ref="multipleTable3"
                                :data="zkbzjtableData"
                                :row-class-name="tableRowClassName"
                                border
                                style="width: 100%"
                                :cell-class-name="cellClsNm"
                                @selection-change="planTableSelect3"
                                :max-height="$store.state.tableHeight"
                                v-sortTable="{ 'tableData': zkbzjtableData, '_this': this, 'ref': 'multipleTable3' }"
                            >
                                <el-table-column type="selection" width="55">
                                </el-table-column>
                                <el-table-column
                                    prop="returnDepositName"
                                    label="名称"
                                    width="270"
                                >
                                </el-table-column>
                                <el-table-column
                                    label="暂扣保证金(元)"
                                    width="150"
                                >
                                    <template v-slot="{ row }">
                                        <el-input
                                            v-model="row.amount"
                                            v-enter-float="{
                                                set: row,
                                                key: 'amount'
                                            }"
                                            @blur="zkbzjchange(row)"
                                            v-if="!isRedSingle"
                                        ></el-input>
                                        <span v-else>{{ row.amount }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    label="截止上期末暂扣保证金(元)"
                                    width="200"
                                >
                                    <template v-slot="{ row }">
                                        {{ row.previousTotalAmount }}
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    label="截止本期末暂扣保证金(元)"
                                    width="200"
                                >
                                    <template v-slot="{ row }">
                                        {{ row.currentTotalAmount }}
                                    </template>
                                </el-table-column>
                                <el-table-column label="说明" width="250">
                                    <template v-slot="{ row }">
                                        <el-input
                                            v-model="row.remarks"
                                            @blur="returnBondBlur(row)"
                                            v-if="!isRedSingle"
                                            type="textarea"
                                            :rows="2"
                                            resize="none"
                                            maxlength="200"
                                        ></el-input>
                                        <span v-else>{{row.remarks}}</span>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                        <div class="lll">^ 返还保证金</div>
                        <div class="e-table" style="min-height: auto">
                            <div class="top" v-if="!isRedSingle">
                                <div class="left">
                                    <div>
                                        <el-button
                                            size="mini"
                                            class="btn-blue"
                                            @click="fhbzjAdd"
                                            >新增行</el-button
                                        >
                                        <el-button
                                            size="mini"
                                            @click="shanchumx4"
                                            >删除</el-button
                                        >
                                    </div>
                                </div>
                            </div>
                            <!-- @cell-mouse-enter="cellMouseEnter"
                                @cell-mouse-leave="cellMouseLeave" -->
                            <el-table
                                ref="multipleTable4"
                                :data="fhbzjtableData"
                                border
                                style="width: 100%"
                                :cell-class-name="cellClsNm"
                                @selection-change="planTableSelect4"
                                :row-class-name="tableRowClassName"
                                :max-height="$store.state.tableHeight"
                                v-sortTable="{ 'tableData': fhbzjtableData, '_this': this, 'ref': 'multipleTable4' }"
                            >
                                <el-table-column type="selection" width="55">
                                </el-table-column>
                                <el-table-column
                                    prop="returnDepositName"
                                    label="名称"
                                    width="270"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="amount"
                                    label="返还保证金(元)"
                                    width="150"
                                >
                                    <template v-slot="{ row }">
                                        <el-input
                                            v-model="row.amount"
                                            v-enter-float="{
                                                set: row,
                                                key: 'amount'
                                            }"
                                            @blur="fhbzjchange(row)"
                                            v-if="!isRedSingle"
                                        ></el-input>
                                        <span v-else>{{ row.amount }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="previousTotalAmount"
                                    label="截止上期末未返还保证金(元)"
                                    width="250"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="currentTotalAmount"
                                    label="截止本期末未返还保证金(元)"
                                    width="250"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="remarks"
                                    label="说明"
                                    width="250"
                                >
                                    <template v-slot="{ row }">
                                        <el-input
                                            v-model="row.remarks"
                                            @blur="returnBondBlur(row)"
                                            v-if="!isRedSingle"
                                            type="textarea"
                                            :rows="2"
                                            resize="none"
                                            maxlength="200"
                                        ></el-input>
                                            <span v-else>{{row.remarks}}</span>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                        <!-- <ComPagination /> -->
                    </div>

                    <!-- 附件信息 -->
                    <div id="accessoryCon" class="con">
                        <div class="tabs-title" id="accessory">附件信息</div>
                        <attach-comp
                            :relationId="attachId"
                            bucketName="turnover"
                            :isView="isRedSingle"
                        />
                    </div>

                    <!-- 审核历史 -->
                    <div id="auditHistoryCon" class="con">
                        <div class="tabs-title" id="auditHistory">审核历史</div>
                        <ComAuditHistoryIndex
                            :billType="1020"
                            :tableData="shenheArr"
                            @getAuditHistory="getauditHistory"
                        />
                    </div>
                </div>
            </el-tabs>
        </div>
        <div id="seat" :style="{ height: seatHeight + 'px' }"></div>
        <div class="buttons">
            <!-- <el-button type="primary" style="background: #2e61d7"
                >打印</el-button
            > -->
            <!-- <el-button
                    type="primary"
                    style="background: #2e61d7"
                    v-if="formData.state == 2 && formData.redBillState == -1"
                    >冲红单</el-button
                > -->
            <exaButtons
                :auditState="auditState"
                :state="formData.state - 0"
                :founderId="formData.founderId"
                @exas="exas"
            ></exaButtons>
            <el-button @click="handleClose">关闭</el-button>
        </div>

        <!-- <span style="display: none">{{ localPopConfirm }}</span> -->
    </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
import { mapMutations, mapState } from 'vuex'
import {
    showPromptPop,
    showSuccessPop,
    showLoading,
    hideLoading,
    openAppClient,
    selectDataClient,
    showErrorPop
} from '@/utils/common'

import { getUuid } from '@/utils/common'
import AttachComp from '@/components/common/attachIndex'
import planRequest from '@/api/turnover/plan.js'
// import { selectDataClient } from '@/utils/common'

import auditRequest from '@/api/materialSettlement/materialProcurement.js'
import publicRequest from '@/api/materialSettlement/public.js'

// import ComAuditHistoryIndex from '@/components/common/exaHistory.vue'
import ComAuditHistoryIndex from '@/pages/materialsmanagement/components/auditHistory/auditHistoryIndex'

import publicReques from '@/api/materialSettlement/public.js'
// import {  showErrorPop } from '@/utils/common'
import exaButtons from '@/components/common/exaButtons'
// import historyUpdateTable from '@/components/common/historyUpdateTable'

export default {
    components: {
        AttachComp,
        ComAuditHistoryIndex,
        exaButtons
        // historyUpdateTable
    },
    data () {
        return {
            //我的数据:↓
            jishunum: 0,
            xxxtentacion: 0,
            nullifyParams: {
                // 作废
                billId: this.$route.query.billid,
                billType: '1020',
                nullifyDescription: '',
                nullifyReason: '',
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: ''
            },
            Thewas: '',
            zkbzjtableData: [],
            fhbzjtableData: [],
            wzlbTableData: [],
            //验证
            rulesBase: {
                billNo: [
                    {
                        required: true,
                        message: '结算编号不能为空',
                        trigger: 'change'
                    }
                ],
                orgName: [
                    {
                        required: true,
                        message: '机构不能为空',
                        trigger: 'change'
                    }
                ],
                amount: [
                    {
                        required: true,
                        message: '结算金额不能为空',
                        trigger: 'change'
                    }
                ],
                settlementDate: [
                    {
                        required: true,
                        message: '结算日期不能为空',
                        trigger: 'change'
                    }
                ],
                businessType: [
                    {
                        required: true,
                        message: '业务类型不能为空',
                        trigger: 'change'
                    }
                ],
                settlementUnitName: [
                    {
                        required: true,
                        message: '结算单位不能为空',
                        trigger: 'change'
                    }
                ],
                acceptancePersonnelName: [
                    {
                        required: true,
                        message: '经办人员不能为空',
                        trigger: 'change'
                    }
                ],
                invoiceNo: [
                    {
                        required: true,
                        message: '发票编号不能为空',
                        trigger: 'change'
                    }
                ],
                taxRate: [
                    {
                        required: true,
                        message: '税率不能为空',
                        trigger: 'change'
                    }
                ],
                taxAmount: [
                    {
                        required: true,
                        message: '税额不能为空',
                        trigger: 'change'
                    }
                ],
                totalAmount: [
                    {
                        required: true,
                        message: '税价合计不能为空',
                        trigger: 'change'
                    }
                ],
                freight: [
                    {
                        required: true,
                        message: '服务费用不能为空',
                        trigger: 'change'
                    }
                ],
                billSource: [
                    {
                        required: true,
                        message: '单据来源不能为空',
                        trigger: 'change'
                    }
                ],
                baseCurRate: [
                    {
                        required: true,
                        message: '本位币汇率不能为空',
                        trigger: 'change'
                    }
                ],
                baseCurName: [
                    {
                        required: true,
                        message: '本位币不能为空',
                        trigger: 'change'
                    }
                ],
                rmbRate: [
                    {
                        required: true,
                        message: '人民币汇率不能为空',
                        trigger: 'change'
                    }
                ],
                offsetAdvancePayment: [
                    {
                        required: true,
                        message: '冲预付款金额不能为空',
                        trigger: 'change'
                    }
                ],
                personalBorrowing: [
                    {
                        required: true,
                        message: '冲个人借支金额不能为空',
                        trigger: 'change'
                    }
                ],
                reversalObjectNumber: [
                    {
                        required: true,
                        message: '冲销对象不能为空',
                        trigger: 'change'
                    }
                ],
                borrowerName: [
                    {
                        required: true,
                        message: '借支人员不能为空',
                        trigger: 'change'
                    }
                ]
            },
            formData: {
                billNo: '', //	结算编号
                orgName: '', //机构name
                orgId: '', //机构id 不显示
                businessType: 0, //业务类型
                sourceBillNo: '', //源单编号
                sourceBillId: '', //元旦id 不显示
                settlementUnitName: '', //结算单位
                settlementUnitId: '', //结算单位id 不显示
                settlementDate: '', //结算日期
                amount: 0, //结算金额 元
                acceptancePersonnelName: '', //经办人员名称
                acceptancePersonnelId: '', //经办人人员id
                invoiceNo: '', //发票编号
                freight: 0, //运输服务费
                taxRate: 0, //税率
                totalAmount: 0, //税价合计
                taxAmount: 0, //税额
                taxDifference: 0, //税额差额
                billSource: 2, //单据来源(1:新增;2:颜结一体)
                billSourcetxt: '验结一体',
                isOffsetAdvancePayment: false, //是否冲预付款 需要转数字
                offsetAdvancePayment: null, // 	冲预付款金额(元)
                isPersonalBorrowing: false, //是否冲个人借资 需要转数字
                acceptanceBillNo: '', //验收编号
                personalBorrowing: 0, //	冲个人借资(元)
                // 1isPersonalBorrowing2personalBorrowing3reversalObjectNumber,reversalObjectId
                //4 borrowerName , borrowerId
                reversalObjectNumber: '', //	冲销对象编号
                reversalObjectId: '', //	冲销对象id 不显示
                currency: '', //币种名称
                currencyId: '', //币种id 不显示
                borrowerName: '', //借资人员名称
                borrowerId: '', //借资人员id 不显示
                baseCurName: '', //本位币名称
                baseCurId: '', //本位币id 不显示
                baseCurRate: 0, //本位币汇率 不显示
                baseCurAmount: 0, //结算金额(本位币)
                remarksL: '', //备注
                state: '0', //单据状态
                founderName: '', //创建人
                founderId: '', //创建人id 不显示
                rmbRate: 0,
                redBillState: null,
                isEndSettle: 0,
                acceptanceBillId: '',
                baseCurTaxAmount: 0,
                baseCurTotalAmount: 0,
                billId: '',
                difference: '',
                currentTotalAmount: '',
                easId: '',
                evaluationLevel: '',
                gmtCreate: '',
                gmtModified: '',
                isRed: 0,
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: '',
                nullifyDescription: '',
                nullifyReason: '',
                purchasingUnitId: '',
                purchasingUnitName: '',
                remarks: '',
                rmbAmount: 0,
                rmbId: '',
                rmbName: '',
                rmbTaxAmount: 0,
                rmbTotalAmount: 0,
                sourceBillName: '',
                sourceId: '',
                sourceNumber: '',
                unoffsetAdvancePayment: null,
                workId: ''
            },
            typeArr: [
                { name: '零星采购计划', id: 0 },
                { name: '物资采购合同', id: 1 },
                { name: '调拔单', id: 2 }
            ],
            viewList: true,
            paginationInfo: {
                total: 1,
                pageSize: 10,
                currentPage: 0
            },
            query: {
                beginPlanDate: '',
                endPlanDate: '',
                keyword: '',
                limit: 0,
                orgId: '',
                page: 1,
                settlementUnitId: '',
                states: []
            }, //搜索
            searchKey: '', //右上角搜索关键字
            tableData: [], //表格
            shenheArr: [],
            serviceFeeData: [],
            serviceFeeData2: [],
            serviceFeeRow: {
                amount: 0, //金额元
                billId: '',
                changeType: 1,
                contractBillId: '',
                contractBillNo: '',
                contractDtlId: '',
                contractDtlName: '',
                dtlId: '',
                invoiceNo: '',
                price: 0, //单价元
                quantity: 0, //数量
                settlementUnitId: '',
                settlementUnitName: '',
                taxAmount: 0, //税额元
                taxRate: 0, //税率%
                totalAmount: 0 // 税价合计
            },
            auditState: {},
            //我的数据:↑
            auditParams: {
                billId: this.$route.query.billid,
                billType: 1020,
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: ''
            },
            tabsName: 'baseInfo',
            userName: '',
            clickId: 'baseInfo',
            tabsNameChild: '',
            childTabClass: '',
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },

            OrgtableData: [], //申报机构数据
            OrgSonTableData: [], //申报机构子列表
            materialsTableData: [], //物资汇总数据
            auditHistoryList: [], //审核历史
            planSelect: [], //申报机构表格明细选择项
            value: '',
            textarea: '',
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            MouseEnterId: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            //基本信息表单数据
            basicFormData: {
                amount: null,
                billId: '',
                billNo: '',
                founderId: '',
                founderName: '',
                gmtCreate: '',
                gmtModified: '',
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: '',
                nullifyDescription: '',
                nullifyReason: '',
                operator: '',
                operatorId: '',
                orgId: '',
                orgName: '',
                remarks: '',
                sourceBillId: '',
                sourceBillNo: '',
                sourceType: null,
                state: '',
                summaryDate: '',
                workId: ''
            },
            objFlag: {
                flag5: false
            },
            orgId: '', //机构id
            orgName: '', //机构名称
            billId: '',
            isSkip: false, //是否跳转
            show: true, //申报机构子列表
            dtlIds: '', //
            //验证
            rules: {
                summaryDate: [
                    {
                        required: true,
                        message: '请输入汇总日期',
                        trigger: 'blur'
                    }
                ],
                currencyId: [
                    { required: true, message: '请选择币种', trigger: 'chenge' }
                ]
            },
            materialsNameData: [], //机构汇总表
            createHistoryData: [], //明细修改历史列表
            errorMsg: [],
            isErrorMsg: true, //是否提醒错误信息
            //我的字段 ↓
            user: '', //当前用户

            //我的字段 ↑
            settlementDeleteData: [],
            isxianshi1: false,
            redBillStateStyle: {
                width: '300px',
                height: '30px',
                color: '#fff',
                backgroundColor: '',
                'text-align': 'center'
            },
            jsdwData: {
                businessUnitTypes: [],
                keyword: '',
                limit: 10,
                orgId: '',
                outerTypes: [],
                page: 1,
                states: [],
                type: [0, 1, 2],
                supplierTypes: [],
                subcontractorTypes: [],
                businessTypes: []
            },
            jsdwIds: null,
            isRedSingle: false,
            settlementSelects: false,
            tableHeadClass: 'cancelClass',
            isOffsetAdvancePayment: 0,
            isPersonalBorrowing: 0,
            isEndSettle: 0,
            isTotalPrice: true,
            currentTotalAmount: 0
        }
    },
    async created () {
        this.billId = this.$route.query.billid
        let data = JSON.parse(localStorage.getItem('vuex'))
        this.orgId = data.userInfo.orgInfo.orgId
        this.user = JSON.parse(localStorage.getItem('vuex'))
        this.billId = this.$route.query.billid
        this.getBasicInfo()
        this.getSettlement()
        this.getServiceFee()
        this.getMargin()
        this.getCurrentUnitInfo()
    },
    methods: {
        ...mapMutations([
            'setPopConfirm',
            'setSelectedInfo',
            'setHistoryTableData',
            'setAuditParams'
        ]),
        // 获取基本信息
        async getBasicInfo () {
            this.formData = await auditRequest.getjibenxixibyId({
                id: this.billId
            })
            if (this.formData.billSource == 2) {
                //单据来源(1:新增;2:颜结一体)
                this.formData.billSourcetxt = '验结一体'
            } else {
                this.formData.billSourcetxt = '新增'
            }
            if (this.formData.redBillState === 3) {
                // 如果是3,说明进入该单据是红单进入到编辑页
                this.businessType = this.typeArr.find(
                    item => item.id === this.formData.businessType
                ).name
                this.formData.currency = this.currencyForm.find(
                    x => x.value == this.formData.currencyId
                ).label
                // 说明当前是红单,需屏蔽按钮,输入框之类的
                this.isRedSingle = true
            }
            // 是否冲预付款
            this.formData.isOffsetAdvancePayment == 1
                ? (this.isOffsetAdvancePayment = true)
                : (this.isOffsetAdvancePayment = false)
            // 是否冲个人借支
            this.formData.isPersonalBorrowing == 1
                ? (this.isPersonalBorrowing = true)
                : (this.isPersonalBorrowing = false)
            // 是否终期结算
            this.formData.isEndSettle == 1
                ? (this.isEndSettle = true)
                : (this.isEndSettle = false)
            // 如果做了冲预付款或冲销完了预付款,则不能勾选中冲预付款
            this.$watch('formData.unoffsetAdvancePayment', () => {
                if (!this.formData.unoffsetAdvancePayment) {
                    this.isOffsetAdvancePayment = false
                }
            })
            // 监听是否勾选冲预付款金额
            this.$watch('isOffsetAdvancePayment', () => {
                if (this.isOffsetAdvancePayment) {
                    // 勾选中,需要带出剩余预付款金额
                    this.formData.offsetAdvancePayment = this.formData.unoffsetAdvancePayment
                } else {
                    this.$refs.rulesBase.clearValidate('offsetAdvancePayment')
                    this.formData.offsetAdvancePayment = 0
                }
            })

            // 监听是否勾选冲个人借支
            this.$watch('isPersonalBorrowing', () => {
                if (!this.isPersonalBorrowing) {
                    this.$refs.rulesBase.clearValidate('personalBorrowing')
                    this.$refs.rulesBase.clearValidate('reversalObjectNumber')
                    this.$refs.rulesBase.clearValidate('borrowerName')
                    this.formData.personalBorrowing = ''
                    this.formData.reversalObjectNumber = ''
                    this.form.reversalObjectId = ''
                    this.formData.borrowerName = ''
                    this.form.borrowerId = ''
                }
            })
            // this.setSelectedInfo({ contractId: this.formData.sourceBillId, orgId: this.orgId })
            // openAppClient('/showSelectedData', '选择结果')
            // this.getUnreversedDownPayments(this.formData.sourceBillId)
        },
        // 获取结算明细数据
        async getSettlement () {
            let wzlbTableData1 = await auditRequest.getmingxibyId({
                id: this.billId
            })
            wzlbTableData1.forEach(item => {
                item.materialClassName = item.topClassName
                item.uuid = getUuid()
                item.isChecked = false
                item.children.forEach(i => {
                    i.uuid = i.dtlId
                    i.parentId = item.topClassId
                })
                const count = +item.children
                    .reduce((prev, c) => (prev += +c.settledAmount || 0), 0)
                    .toFixed(2)
                item.materialName = `金额小计： ${count}`
            })

            this.wzlbTableData = wzlbTableData1
        },
        // 获取服务费用
        async getServiceFee () {
            this.serviceFeeData = await auditRequest.getfuwufeiyongbyId({
                id: this.billId
            })
            if (this.serviceFeeData instanceof Array) {
                console.log('hishuzu1')
            } else {
                this.serviceFeeData = []
                console.log('889', this.serviceFeeData)
            }
        },
        // 获取保证金
        async getMargin () {
            this.bzjarr = await auditRequest.getbaozhenjinbyId({
                id: this.billId
            })
            if (this.bzjarr.length > 0) {
                for (let i = 0; i < this.bzjarr.length; i++) {
                    if (this.bzjarr[i].returnDepositType == 1) {
                        //暂扣保证金
                        this.zkbzjtableData.push(this.bzjarr[i])
                    } else {
                        //返还保证金
                        this.fhbzjtableData.push(this.bzjarr[i])
                    }
                }
            }
        },
        // 获取未冲销预付款
        async getUnreversedDownPayments (contractId) {
            // this.setSelectedInfo({ contractId: contractId, orgId: this.orgId })
            // openAppClient('/showSelectedData', '选择结果')
            let res = await auditRequest.getRemainingPrepaymentAmount({ contractId: contractId, orgId: this.orgId }) //未冲预付款金额
            // this.setSelectedInfo(res)
            // openAppClient('/showSelectedData', '选择结果')
            if (typeof res === 'object') {
                this.formData.unoffsetAdvancePayment = 0
            } else {
                this.formData.unoffsetAdvancePayment = res
            }
        },
        // 冲预付款金额失去焦点时
        offsetAdvancePaymentBlur (val) {
            if (+val && +val <= +this.formData.unoffsetAdvancePayment) {
                this.formData.offsetAdvancePayment = val
            } else {
                this.formData.offsetAdvancePayment = +this.formData.unoffsetAdvancePayment
                this.clientPop(
                    'err',
                    `需要大于0,小于等于未冲销的预付金额${this.formData.unoffsetAdvancePayment}`
                )
            }
        },
        // 勾选冲个人借支,勾选上后提示“确认冲个人借资？”，确认则勾选，取消则不勾选；
        isPersonalBorrowingChange (val) {
            if (val) {
                this.clientPop(
                    'info',
                    '确认冲个人借资？',
                    () => {},
                    null,
                    () => {
                        this.isPersonalBorrowing = false
                    }
                )
            }else {
                this.formData.personalBorrowing = ''
                this.formData.reversalObjectNumber = ''
                this.form.reversalObjectId = ''
                this.formData.borrowerName = ''
                this.form.borrowerId = ''
            }
        },
        // 勾选了“冲个人借支”后，才可填写“冲个人借支金额”，且填写的金额必须小于等于本次的税价合计
        personalBorrowingBlur () {
            if (this.formData.personalBorrowing > this.shuijiaheji) {
                this.clientPop(
                    'err',
                    `冲个人借支金额必须小于等于本次的税价合计${this.shuijiaheji}`
                )
                this.formData.personalBorrowing = this.shuijiaheji
            }
        },
        // // 勾选终期结算后,给出提示
        isEndSettleChange (val) {
            if (val) {
                this.clientPop(
                    'info',
                    '是否终期结算，终期结算后不能再对结算单位进行结算？',
                    () => {},
                    null,
                    () => {
                        this.isEndSettle = false
                    }
                )
            }
        },
        //我的方法 ↓
        shuilvchang () {
            if (
                this.formData.taxRate - 0 >= 0 &&
                this.formData.taxRate - 0 <= 100
            ) {
                this.$set(
                    this.formData,
                    'taxRate',
                    +(+this.formData.taxRate).toFixed(2)
                )

                this.formData.taxAmount = +(
                    (this.formData.taxRate / 100) *
                    this.jiesuanjine
                ).toFixed(2)
            } else {
                showErrorPop('税率只能在0-100之间,请检查！')
                this.$set(this.formData, 'taxRate', 0)

                this.formData.taxAmount = +(
                    (this.formData.taxRate / 100) *
                    this.jiesuanjine
                ).toFixed(2)
            }
            // 税率变化,结算明细中税额和税额差额会变化,从而基本信息中税额差额会变化
            this.wzlbTableData.forEach(item => {
                item.children.forEach(it => {
                    it.taxDifference = +(
                        it.settledAmount * (this.formData.taxRate / 100) -
                        it.acceptanceTaxAmount
                    ).toFixed(2)
                })
            })
        },

        async exas (arg) {
            if (arg === 'submit') {
                console.log('1') // 保存所有数据
                for (let i = 0; i < this.wzlbTableData.length; i++) {
                    for (
                        let j = 0;
                        j < this.wzlbTableData[i].children.length;
                        j++
                    ) {
                        if (
                            this.wzlbTableData[i].children[j].settledQuantity <=
                            0
                        ) {
                            showErrorPop('结算数量小于或等于0,请检查！')
                            return
                        }
                    }
                }
                if (this.formData.invoiceNo - 0 > 0) {
                    console.log(' xxxx', this.zkbzjtableData)
                } else {
                    showErrorPop('发票编号只能为数字,请检查！')
                    return
                }

                await this.submit()
            } else if (arg === 'submitCommit') {
                for (let i = 0; i < this.wzlbTableData.length; i++) {
                    for (
                        let j = 0;
                        j < this.wzlbTableData[i].children.length;
                        j++
                    ) {
                        if (
                            this.wzlbTableData[i].children.settledQuantity <= 0
                        ) {
                            showErrorPop('结算数量小于或等于0,请检查！')
                            return
                        }
                    }
                }
                if (this.formData.invoiceNo - 0 > 0) {
                    console.log(' xxxx', this.zkbzjtableData)
                } else {
                    showErrorPop('发票编号只能为数字,请检查！')
                    return
                }
                await this.submitCommit()
            } else if (arg === 'audit') {
                console.log('3') // 审核
                await this.shenhe()
            } else if (arg === 'undoAudit') {
                await this.nullify() // 撤销审核
            } else if (arg === 'nullify') {
                console.log('5') // 作废(
                await this.zuofei()
            } else if (arg === 'deleteData') {
                console.log('6') // 删除
                await this.shanchu1()
            }
        },
        zuofei () {
            showLoading()
            hideLoading()
            this.setAuditParams(this.nullifyParams)
            // 客户端弹窗弹出本地页面
            openAppClient('/nullifyDialog', '单据作废原因', () => {
                const auditParams = JSON.parse(localStorage.vuex).auditParams
                // this.setSelectedInfo(auditParams)
                // // 客户端弹窗预览结果
                // // 参数依次为: 打开页面地址、标题、回调函数
                // openAppClient('/showSelectedData', '选择结果', function () {
                //     // alert('关闭后回调')
                // })
                showLoading()
                publicRequest
                    .zuofei(auditParams)
                    .then(() => {
                        this.clientPop('suc', '作废成功', this.handleClose)
                    })
                    .finally(() => {
                        hideLoading()
                    })
            }, null, null, null, 'small')
        },
        async shanchu1 () {
            this.clientPop(
                'info',
                '确认删除这条数据吗？此操作不可逆转!',
                async () => {
                    await auditRequest.shanchucgjs({
                        id: this.$route.query.billid
                    })
                    this.clientPop('suc', '删除成功')
                    this.handleClose()
                }
            )
            // await auditRequest.shanchucgjs({ id: this.billId })
            // this.clientPop('suc', '删除成功', this.handleClose)
        },
        shenhe () {
            console.log('审核')
            openAppClient('/exaDialog', '填写审核意见', () => {
                const auditParams = JSON.parse(localStorage.vuex).auditParams
                // 将审核意见赋值给参数传给后端
                publicReques
                    .goaudit({
                        billId: this.billId,
                        billType: '1020',
                        isPass: auditParams.isPass,
                        isShareInAudit: false,
                        opinion: auditParams.opinion
                    })
                    .then(() => {
                        this.clientPop('suc', '审核成功')
                        this.$router.replace('/materialProcurementList')
                    })
                    .catch(() => {
                        this.clientPop('suc', '审核失败')
                    })
            }, null, null, null, 'small')
        },
        async nullify () {
            console.log('撤回')
            await publicReques.goBack({
                billId: this.billId,
                billType: '1020'
            })
            this.clientPop('suc', '撤回成功')
            this.$router.replace('/materialProcurementList')
        },
        chakan11 () {
            console.log(this.wzlbTableData)
        },
        zkbzjchange (row) {
            row.changeType === 1 ? row.changeType = 1 : row.changeType = 2
            row.currentTotalAmount = +(+row.previousTotalAmount + +row.amount).toFixed(2)
        },
        returnBondBlur (row) {
            row.changeType === 1 ? row.changeType = 1 : row.changeType = 2
        },
        fhbzjchange (row) {
            row.changeType === 1 ? row.changeType = 1 : row.changeType = 2
            row.currentTotalAmount = +(+row.previousTotalAmount - +row.amount).toFixed(2)
        },
        // 新增返还保证金
        fhbzjAdd () {
            selectDataClient({
                SelectServiceToken:
                    '/materialsettle/purchaseSettlement/listUnreturnAmountForSelect', // 客户端对应方法名
                IsSingleMode: false, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
                InitParamsStr: this.formData.sourceBillId, // 接口参数(name为模拟参数) // TODO: 传参不对
                Title: '选择返还保证金' // 标题
            }).then(val => {
                let result = val.map(item => {
                    return {
                        amount: '',
                        billId: this.billId,
                        changeType: 1,
                        currentTotalAmount: '', // 截止本期末未返还保证金(元)
                        dtlId: '',
                        previousTotalAmount: item.unreturnAmount, //截止上期末未返还保证金(元)
                        remarks: '',
                        returnDepositId: item.returnDepositId,
                        returnDepositName: item.returnDepositName,
                        returnDepositType: 2,
                    }
                })
                result.forEach(item => {
                    const isPush = this.fhbzjtableData.every(it => it.returnDepositId !== item.returnDepositId)
                    if(isPush) {
                        this.fhbzjtableData.push(item)
                    }else {
                        const all = this.fhbzjtableData.filter(its => its.returnDepositId === item.returnDepositId)
                        let noPush = all.some(i => i.changeType !== -1)
                        if(!noPush) {
                            this.fhbzjtableData.push(item)
                        }
                    }
                })
            })
        },
        // 新增暂扣保证金
        addzkbzj () {
            let data = JSON.parse(localStorage.getItem('vuex'))
            const orgid = data.userInfo.orgInfo.orgId
            let ids = this.zkbzjtableData.map(item => item.returnDepositId)
            selectDataClient({
                SelectServiceToken: '/subcontract/basicSettingsBond/getBond', // 客户端对应方法名
                IsSingleMode: false, // 是否单选 true 单选 false 多选
                SelectedIDs: ids, // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
                InitParamsStr: JSON.stringify({
                    orgId: orgid,
                    contractCategoryName: '物资采购合同'
                }), // 接口参数(name为模拟参数)
                Title: '选择暂扣保证金' // 标题
            }).then(val => {
                // this.setSelectedInfo(val)
                // openAppClient('/showSelectedData', '选择结果')

                let result = val.map(item => {
                    return {
                        amount: '',
                        billId: this.billId,
                        changeType: 1,
                        currentTotalAmount: '', // 截止本期末暂扣保证金(元)
                        dtlId: '',
                        previousTotalAmount: '', //截止上期末暂扣保证金(元)
                        remarks: '',
                        returnDepositId: item.billId,
                        returnDepositName: item.name,
                        returnDepositType: 1,
                    }
                })
                result.forEach(item => {
                    const isPush = this.zkbzjtableData.every(it => it.returnDepositId !== item.returnDepositId)
                    if(isPush) {
                        this.zkbzjtableData.push(item)
                    }else {
                        const all = this.zkbzjtableData.filter(its => its.returnDepositId === item.returnDepositId)
                        let noPush = all.some(i => i.changeType !== -1)
                        if(!noPush) {
                            this.zkbzjtableData.push(item)
                        }
                    }
                })
            })
        },
        shuiechang () {
            // console.log(nbf)
            const str = this.formData.taxAmount + ''
            if (str.length > 14) {
                showErrorPop('税额不能超过14位数,请检查！')
                this.formData.taxAmount = 0
                return
            }
            this.formData.taxAmount = +(+this.formData.taxAmount).toFixed(2)
        },
        panduanzhengshu () {
            if (this.formData.offsetAdvancePayment > 0) {
                console.log('进入判断444')
            } else {
                this.formData.offsetAdvancePayment = 0
                showErrorPop('冲预付款金额必须为整数,请重新填写!')
            }
        },
        gaibian (obj, type) {
            //未结算数量unsettledQuantity 结算数量settledQuantity 验收金额acceptanceAmount 单价settledPrice 金额settledAmount 差额difference 税额差额taxDifference

            //formData.taxAmount税额   formData.taxRate税率

            if (type == '数量') {
                if (obj.unsettledQuantity < obj.settledQuantity) {
                    obj.settledQuantity = obj.unsettledQuantity
                    showErrorPop(
                        '结算数量不能超过未结算数量,系统已为您填写最大值'
                    )
                }
            }

            //未结算数量unsettledQuantity 结算数量settledQuantity 验收金额acceptanceAmount 单价settledPrice 金额settledAmount 差额difference 税额差额taxDifference
            // 差额difference 税额差额 taxDifference
            // settledAmount
            // taxDifference
            if (+obj.settledAmount && +obj.settledQuantity) {
                // 单价
                obj.settledPrice = +(
                    obj.settledAmount / obj.settledQuantity
                ).toFixed(2)

                // 税额差额 = 结算税额 - 验收税额
                // 结算税额 = 当前行结算金额 * 基本信息中的税率
                obj.taxDifference = +(
                    obj.settledAmount * (this.formData.taxRate / 100) -
                    obj.acceptanceTaxAmount
                ).toFixed(2)

                // 金额小计需跟随变化
                let count = 0
                this.wzlbTableData.forEach(item => {
                    count = +item.children
                        .reduce((prev, c) => (prev += +c.settledAmount || 0), 0)
                        .toFixed(2)
                    item.materialName = `金额小计： ${count}`
                })
            }

            // 如果结算数量和验收数量不一样
            if(obj.settledQuantity !== obj.unsettledQuantity) {
                obj.acceptanceAmount = +(obj.acceptancePrice * obj.settledQuantity).toFixed(2)
            }
            // // 差额
            obj.difference = +(obj.settledAmount - obj.acceptanceAmount).toFixed(2)

            this.jishunum = 0
            this.formData.taxDifference = 0
            this.formData.taxAmount = 0
            for (let i = 0; i < this.wzlbTableData.length; i++) {
                for (
                    let j = 0;
                    j < this.wzlbTableData[i].children.length;
                    j++
                ) {
                    // this.formData.taxAmount +=  this.wzlbTableData[i].children[j].settledAmount - 0 || 0
                    this.formData.taxAmount = +(
                        (this.formData.taxRate / 100) *
                        this.jiesuanjine
                    ).toFixed(2)
                    this.formData.taxDifference += +(
                        this.wzlbTableData[i].children[j].taxDifference - 0 || 0
                    ).toFixed(2)
                }
            }

            this.formData.taxAmount = +(+this.formData.taxAmount).toFixed(2)
        },

        shuieheji (row) {
            if (+row.amount && +row.taxRate) {
                row.taxAmount = +(+row.amount * (+row.taxRate / 100)).toFixed(2)
            } else {
                row.taxAmount = 0
            }
            if (+row.amount && +row.taxAmount) {
                row.totalAmount = +(+row.amount + +row.taxAmount).toFixed(2)
            } else {
                row.totalAmount = 0
            }
        },

        danjia (row, type) {
            // price 单价 taxAmount税额  totalAmount 税额合计
            console.log(row)
            console.log(type)

            if (+row.contractQuantity && (+row.quantity > +row.contractQuantity)) {
                this.clientPop(
                    'err',
                    `不能大于合同数量${row.contractQuantity}`
                )
                row.quantity = row.contractQuantity
            }
            if (+row.amount && +row.quantity) {
                row.price = +(row.amount / row.quantity).toFixed(2)
            } else {
                row.price = 0
            }
            if (+row.amount && +row.taxRate) {
                row.taxAmount = +(+row.amount * (+row.taxRate / 100)).toFixed(
                    2
                )
            } else {
                row.taxAmount = 0
            }
            if (+row.amount && +row.taxAmount) {
                row.totalAmount = +(+row.amount + +row.taxAmount).toFixed(2)
            } else {
                row.totalAmount = 0
            }
        },
        // 税率只能输入0-100的数
        onInput0_100 (e) {
            this.$message.closeAll()
            if (e.target.value < 0 || e.target.value > 100) {
                this.clientPop('err', '只能输入[0,100]区间的数')
            }
            e.target.value =
                (e.target.value >= 0 &&
                    e.target.value <= 100 &&
                    e.target.value.match(/^\d{1,3}(\.\d*)?$/)[0]) ||
                null
        },
        //选择借支人员
        xzjzry () {
            //  borrowerName: '', //借资人员名称
            //  borrowerId: '', //借资人员id 不显示
            selectDataClient({
                SelectServiceToken: '/hr/user/getUserUnderOrgPage', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id
                Title: '借支人员选择' // 标题
            }).then(val => {
                // 保存用户选择返回数据到store
                // this.setSelectedInfo(val)
                // // 客户端弹窗预览结果
                // // 参数依次为: 打开页面地址、标题、回调函数
                // openAppClient('/showSelectedData', '选择结果', function () {
                //     // alert('关闭后回调')
                // })
                if (val.length > 0) {
                    this.formData.borrowerName = val[0].userName
                    this.form.borrowerId = val[0].userId
                }
            })
        },
        //选择冲销对象
        xzcxdx () {
            if (
                !this.isPersonalBorrowing ||
                !this.shuijiaheji ||
                !this.yunshufuwufeiyong
            ) {
                return this.clientPop(
                    'err',
                    '勾选个人借支并且有税价合计和服务费,才可选择冲销对象'
                )
            }
            // 弹窗选择数据
            selectDataClient({
                SelectServiceToken:
                    '/facilityconnect/lease/receive/plan/contract/receive', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
                InitParamsStr: JSON.stringify({ billId: this.billId }), // 接口参数(name为模拟参数)
                Title: '选择机构用户' // 标题
            }).then(val => {
                // 保存用户选择返回数据到store
                // this.setSelectedInfo(val)
                // // 客户端弹窗预览结果
                // // 参数依次为: 打开页面地址、标题、回调函数
                // openAppClient('/showSelectedData', '选择结果', function () {
                //     // alert('关闭后回调')
                // })
                if (val.length > 0) {
                    this.formData.reversalObjectNumber = val[0].leaseUnit
                    this.form.reversalObjectId = val[0].leaseUnitId
                }
            })
        },
        chakand () {
            console.log(this.Thewas)
            console.log(this.Thewas != 'add')
        },
        // inputchanger1 (e) {
        //     console.log('111', e)
        //     if(e == 2 || e == 3) {
        //         this.formData.isPersonalBorrowing = false
        //         this.formData.personalBorrowing = 0
        //         this.formData.reversalObjectNumber = ''
        //         this.formData.reversalObjectId = ''
        //         this.formData.borrowerName = ''
        //         this.formData.borrowerId = ''
        //     }
        // },
        inputchanger2 (e) {
            console.log('111', e)

            // this.clientPop('info', '确认提示信息', this.callback, null, this.cancelCallBack)
            if (e == false) {
                this.formData.personalBorrowing = 0
                this.formData.reversalObjectNumber = ''
                this.formData.reversalObjectId = ''
                this.formData.borrowerName = ''
                this.formData.borrowerId = ''
            }
        },

        invoiceNoBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
        },
        contractDtlNameBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
        },
        // 数量变化时
        quantityBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
            // // 不能超过合同数量
            if (row.quantitys) {
                if (row.quantity > row.quantitys) {
                    row.quantity = row.quantitys
                }
            }
            if (!!row.amount && !!row.quantity) {
                row.price = +row.amount / +row.quantity
            }
        },
        // 金额变化时
        amountBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
            if (!!row.amount && !!row.quantity) {
                row.price = +row.amount / +row.quantity
            }
            if (!!row.amount && !!row.taxRate) {
                row.taxAmount = row.amount * row.taxRate
            }
            if (!!row.amount && !!row.taxAmount) {
                row.totalAmount = row.amount + row.taxAmount
            }
            // this.basicFormData.freight = +(this.serviceFeeData.reduce(
            //     (pre, c) => (pre += +c.amount || 0),
            //     0
            // )).toFixed(2)
        },
        // 税率变化时
        taxRateBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
            if (!!row.amount && !!row.taxRate) {
                row.taxAmount = row.amount * row.taxRate
            }
            if (!!row.amount && !!row.taxAmount) {
                row.totalAmount = row.amount + row.taxAmount
            }
        },
        //税额变化时
        taxAmountBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
            if (!!row.amount && !!row.taxAmount) {
                row.totalAmount = +row.amount + +row.taxAmount
            }
        },
        serviceFeeDelete (row, index) {
            // this.fuwufeiyongarr.splice(index, 1)
            row.changeType = -1
            row.amount = 0
            console.log(index)
            console.log(row)
            // this.serviceFeeData.splice(1, index)
            // this.serviceFeeData2.push(row)
        },
        async contractDialog (row, index) {
            let contracted = {
                contractId: row.contractBillId,
                contractType: row.contractBillType || 0
            }
            let res = await auditRequest.getContract(
                { orgid: this.orgId, contractId: this.formData.sourceBillId, contractType: '1'  },
                contracted
            )
            let result
            // 如果选择的是合同并且合同下有清单,则需带入合同下的清单
            if (res.list && res.list.length > 0) {
                result = res.list.map(item => {
                    return {
                        amount: null,
                        // billId: this.billid,
                        billId: this.billid || '',
                        changeType: 1,
                        contractBillId: res.contractId,
                        contractBillNo: res.contractNumber,
                        contractBillType: res.contractType,
                        contractDtlId: item.detailedId,
                        contractDtlName: item.name,
                        contractQuantity: item.quantity,
                        dtlId: '',
                        invoiceNo: '',
                        price: null,
                        quantity: item.quantity,
                        settlementUnitId: res.secondPartyId,
                        settlementUnitName: res.secondPartyName,
                        sourceServiceFeeDtlId: '',
                        taxAmount: 0,
                        taxRate: res.taxRate,
                        totalAmount: 0
                    }
                })
                let _arr = []
                result.forEach(item => {
                    const shouldPush = this.serviceFeeData.every(
                        it => item.contractDtlId !== it.contractDtlId
                    )
                    if (shouldPush) {
                        _arr.push(item)
                    } else {
                        // 找到了清单ID相同
                        const repeatArr = this.serviceFeeData.filter(
                            i => item.contractDtlId === i.contractDtlId
                        )
                        const noPush = repeatArr.some(
                            _its => _its.changeType !== -1
                        )
                        if (!noPush) {
                            _arr.push(item)
                        }
                    }
                })
                if (_arr.length !== 0) {
                    this.serviceFeeData.splice(index, 1, ..._arr)
                }
            } else {
                // 如果选择的合同没有清单
                result = {
                    amount: null,
                    billId: this.billid,
                    changeType: 1,
                    contractBillId: res.contractId,
                    contractBillNo: res.contractNumber,
                    contractBillType: res.contractType,
                    contractDtlId: '',
                    contractDtlName: '',
                    contractQuantity: '',
                    dtlId: '',
                    invoiceNo: '',
                    price: null,
                    quantity: null,
                    settlementUnitId: res.secondPartyId,
                    settlementUnitName: res.secondPartyName,
                    sourceServiceFeeDtlId: '',
                    taxAmount: 0,
                    taxRate: res.taxRate,
                    totalAmount: 0
                }
                const shouldPush = this.serviceFeeData.every(
                    it => it.contractBillId !== result.contractBillId
                )
                if (shouldPush) {
                    this.serviceFeeData.splice(index, 1, result)
                } else {
                    const repeatArr = this.serviceFeeData.filter(
                        i => i.contractBillId === result.contractBillId
                    )
                    const noPush = repeatArr.some(
                        _its => _its.changeType !== -1
                    )
                    if (!noPush) {
                        this.serviceFeeData.splice(index, 1, result)
                    }
                }
            }
        },
        async billingUnitDialog (row, index) {
            this.jsdwIds = row.settlementUnitId
            let res = await auditRequest.getBillingUnit(
                this.jsdwData,
                this.jsdwIds
            )
            // async getServeList () { // 弹窗好了,需删除这行
            //     let res = await request.getServeList(this.billingUnitQuery) // 弹窗好了,需删除这行
            let result = {
                amount: null,
                billId: this.billid,
                changeType: 1,
                contractBillId: '',
                contractBillNo: '',
                contractBillType: 0,
                contractDtlId: '',
                contractDtlName: '',
                contractQuantity: '',
                dtlId: '',
                invoiceNo: '',
                price: null,
                quantity: null,
                settlementUnitId: res.id,
                settlementUnitName: res.outerName,
                sourceServiceFeeDtlId: '',
                taxAmount: 0,
                taxRate: 0,
                totalAmount: 0
            }
            const shouldPush = this.serviceFeeData.every(
                it => it.settlementUnitId !== result.settlementUnitId
            )
            if (shouldPush) {
                this.serviceFeeData.splice(index, 1, result)
            } else {
                const repeatArr = this.serviceFeeData.filter(
                    i => i.settlementUnitId === result.settlementUnitId
                )
                const noPush = repeatArr.some(_its => _its.changeType !== -1)
                if (!noPush) {
                    this.serviceFeeData.splice(index, 1, result)
                }
            }
            // this.basicFormData.freight = +(this.serviceFeeData.reduce(
            //     (pre, c) => (pre += +c.amount || 0),
            //     0
            // )).toFixed(2)
        },
        serviceFeeAdd () {
            // alert('111', this.serviceFeeData)
            console.log('新增', this.serviceFeeData)
            // this.serviceFeeData.push(this.serviceFeeRow)
            // 弹窗选择数据
            if (this.wzlbTableData.length && this.wzlbTableData.length > 0) {
                this.serviceFeeData.push({
                    amount: 0, //金额元
                    billId: '',
                    changeType: 1,
                    contractBillId: '',
                    contractBillNo: '',
                    contractBillType: 0,
                    contractDtlId: '',
                    contractDtlName: '',
                    dtlId: '',
                    invoiceNo: '',
                    price: 0, //单价元
                    quantity: 0, //数量
                    settlementUnitId: '',
                    settlementUnitName: '',
                    taxAmount: 0, //税额元
                    taxRate: 0, //税率%
                    totalAmount: 0, // 税价合计
                    uuid: getUuid()
                })
            } else {
                showErrorPop('结算明细不能为空')
            }
        },
        xzry () {
            selectDataClient({
                SelectServiceToken: '/hr/user/getUserUnderOrgPage', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id
                Title: '人员选择' // 标题
            }).then(val => {
                if (val.length > 0) {
                    this.$set(
                        this.formData,
                        'acceptancePersonnelName',
                        val[0].userName
                    )
                    this.$set(
                        this.formData,
                        'acceptancePersonnelId',
                        val[0].userId
                    )
                }
            })
        },
        //审核历史
        async getauditHistory () {
            console.log('1111111')
            if (this.billId !== '') {
                console.log('2222')
                const data = await publicReques.getauditHistory({
                    billId: this.billId,
                    billType: 1020,
                    freeNextUnitIndex: 0,
                    freeNextUser: '',
                    isPass: true,
                    isShareInAudit: true,
                    opinion: ''
                })
                console.log('iop', data)
                // for(let i = 0 ; i < data.length ; i++) {
                //     this.shenheArr.push(data[i])
                // }
                this.shenheArr = [...data]
                console.log('xxx', this.shenheArr)
            }
        },
        async xzjsmx () {
            let data = JSON.parse(localStorage.getItem('vuex'))
            const orgid = data.userInfo.orgInfo.orgId
            selectDataClient({
                SelectServiceToken:
                    '/materialsettle/acceptance/listUnsettleMaterialByFilterForSelect', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
                InitParamsStr: JSON.stringify({
                    businessType: this.formData.businessType,
                    keyWord: '',
                    orgId: orgid,
                    parentId: '0',
                    settleUnitId: '',
                    sourceBillId: ''
                }), // 接口参数(name为模拟参数)
                Title: '选择结算明细' // 标题
            }).then(res => {
                // this.setSelectedInfo(res)
                // openAppClient('/showSelectedData', '数组')
                if (res.length < 1) {
                    this.clientPop('err', '请选择结算明细！')
                    return
                }
                // 判断是否同一个源单的数据,如果不是同一个源单,需提示用户
                // this.setSelectedInfo(res)
                // openAppClient('/showSelectedData', '数组')
                let isSameContract = res.some(
                    item => res[0].sourceBillNo !== item.sourceBillNo
                )
                if (isSameContract) {
                    this.clientPop(
                        'err',
                        '只能选择相同合同的物资，请重新选择！'
                    )
                    return
                }

                let data = res.find(item => item.parentId != 0)
                if (!res) {
                    return
                } else {
                    // 如果结算单位和结算明细是空的情况,直接添加数据
                    if (
                        this.wzlbTableData.length < 1 &&
                        !this.formData.settlementUnitId
                    ) {
                        this.basicDataFun(data)
                        this.wzlbTableData = this.settlementFun(res)
                    } else if (
                        this.formData.sourceBillNo &&
                        (this.formData.sourceBillNo !== data.sourceBillNo)
                    ) {
                        // 如果选择的源单不同,需提示用户,如果确定则覆盖原有结算明细和基本信息
                        this.clientPop(
                            'info',
                            '当前选择源单与原有源单不同,若点击确定,原有基本信息和结算明细将被覆盖!',
                            () => {
                                this.jgdwChange() // 将原数组的changeType置为1或删除
                                this.basicDataFun(data) // 带出基本信息某些数据
                                this.settlementPush(res) // 将数据添加至表格
                            }
                        )
                    } else {
                        this.basicDataFun(data)
                        // 此情况为同一个合同的情况
                        this.settlementPush(res)
                    }
                }
                let count = 0
                this.wzlbTableData.forEach(item => {
                    count = +item.children
                        .reduce((pre, c) => (pre += +c.settledAmount || 0), 0)
                        .toFixed(2)
                    item.materialName = `金额小计： ${count}`
                })
                // res = []
                // for(let i = 0 ; i < res.length ; i++) {
                //     if( res[i].parentId != '0' && res[i].parentId != 0) {
                //         res.push(res[i])
                //     }
                // }
                // // res = [res]
                // const mapObj = {}
                // let arr = []
                // res.forEach(e => {
                //     // alert('1')
                //     // this.setSelectedInfo(e)
                //     // // 客户端弹窗预览结果
                //     // // 参数依次为: 打开页面地址、标题、回调函数
                //     // openAppClient('/showSelectedData', '选择结果', function () {
                //     // // alert('关闭后回调')
                //     // })
                //     const children = []
                //     e.materialClassNameArr = e.materialClassName.split('/')
                //     e.materialClassIdArr = e.materialClassId.split('/')
                //     // alert('111')
                //     let obj
                //     const topClassId = e.materialClassIdArr.splice(0, 1).toString()
                //     const topClassName = e.materialClassNameArr.splice(0, 1).toString()
                //     if (!mapObj[topClassId]) {
                //         obj = {
                //             topClassId,
                //             topClassName,
                //             customId: topClassId,
                //             materialClassId: topClassId,
                //             materialClassName: topClassName,
                //             uuid: getUuid(),
                //             totalAmount: null,
                //             totalQuantity: null,
                //         }
                //         //这里需要改成push多个对象   还没改
                //         arr.push(obj)

                //         mapObj[topClassId] = obj
                //     } else {
                //         obj = mapObj[topClassId]
                //     }

                //     children.push({
                //         // settledAmount金额 settledQuantity结算数量 settledPrice单价 taxDifference税额差价

                //         uuid: getUuid(),
                //         billId: this.billId || '',
                //         billNo: this.basicFormData.billNo || '',
                //         customId: getUuid(),
                //         warehouse: e.warehouse,
                //         unsettledQuantity: (e.unsettledQuantity - 0) || 0, //未结算数量
                //         acceptedQuantity: null, //已验收数量
                //         changeType: 1,
                //         dtlId: e.dtlId, //加工收料明细id
                //         materialClassId: e.materialClassIdArr.join('/'), //物资类别id(
                //         materialClassName: e.materialClassNameArr.join('/'), //物资类别名称
                //         materialName: e.materialName, //物资名称
                //         settledPrice: 0, //单价
                //         quantity: e.surplusQuantity, //数量
                //         spec: e.spec, //规格型号
                //         texture: e.texture, //材质
                //         unit: e.unit, //计量单位
                //         warehouseId: e.warehouseId, //仓库id
                //         warehouseName: e.warehouseName, //仓库名称
                //         settledQuantity: (e.unsettledQuantity - 0) || 0, //结算数量
                //         settledAmount: 0, //金额
                //         acceptanceAmount: e.acceptanceAmount, //验收金额
                //         difference: 0, //差额
                //         taxDifference: 0, //税价差额
                //         id: e.id,
                //         // materialId:e.materialId
                //         acceptanceDtlId: e.dtlId, // 物资验收明细Id
                //         sourceDtlId: e.sourceDtlId, //源单明细id
                //         materialId: e.materialId, //物资id
                //         taxRate: e.taxRate || 100,
                //         price: e.price || 0
                //         // materialId:e.materialId
                //         // sourceDtlId
                //         // unsettledQuantity: 0 //未结算数量

                //     })
                //     obj.children = !obj.children
                //         ? children
                //         : obj.children.concat(children)
                //     // 统计小计
                //     const count = obj.children.reduce(
                //         (prev, c) => (prev += c.amount || 0),
                //         0
                //     )
                //     obj.materialName = `小计： ${count}`
                //     obj.children = this.uniqueArray(obj.children, 'customId')
                // })
                // this.wzlbTableData = arr
            })
            // wzlbTableData
        },
        // 根据选择的结算明细,带出基本信息中的某些数据
        basicDataFun (res) {
            this.$set(this.formData, 'settlementUnitName', res.supplierName)
            this.$set(this.formData, 'settlementUnitId', res.supplierId)

            this.$set(this.formData, 'sourceBillNo', res.sourceBillNo)
            this.$set(this.formData, 'sourceBillId', res.sourceBillId)
            this.$set(this.formData, 'sourceBillName', res.sourceBillName)

            this.$set(this.formData, 'acceptanceBillId', res.billId) // 验收id
            this.$set(this.formData, 'acceptanceBillNo', res.billNo) // 验收编号

            //接口还没更新 更新了 取消注释 ↓
            this.$set(this.formData, 'currency', res.currency)
            this.$set(this.formData, 'currencyId', res.currencyId)

            this.$set(this.formData, 'baseCurName', res.baseCurName)
            this.$set(this.formData, 'baseCurId', res.baseCurId)

            this.$set(this.formData, 'taxRate', res.taxRate || 0)

            // baseCurRate 本位币  rmbRate人民币
            this.$set(this.formData, 'baseCurRate', res.baseCurRate)
            this.$set(this.formData, 'rmbRate', res.rmbRate)

            this.$set(this.formData, 'offsetAdvancePayment', 0)
            this.isEndSettle = false

            // 本位币汇率 formData.baseCurRate baseCurName本位比 currency币种
            if (this.formData.baseCurName == this.formData.currency) {
                this.formData.baseCurRate = 1
                this.formData.rmbRate = 1
                this.isxianshi1 = false
            } else {
                this.isxianshi1 = true
            }
            // 获取剩余预付款金额
            this.getUnreversedDownPayments(res.sourceBillId)
        },
        // 将选择的结算明细处理为需要的格式
        settlementFun (res) {
            const newArr = []
            let obj = {}
            res.forEach(item => {
                if (item.materialClassName) {
                    const topClassName = item.materialClassName.split('/')[0]
                    const topClassId = item.materialClassId.split('/')[0]
                    obj = {
                        topClassId,
                        topClassName,
                        customId: topClassId,
                        materialClassId: topClassId,
                        materialClassName: topClassName,
                        uuid: getUuid(),
                        totalAmount: null,
                        totalQuantity: null,
                        isChecked: false,
                        children: []
                    }
                    if (newArr.length < 1) {
                        newArr.push(obj)
                    } else {
                        let isParent = newArr.every(
                            itm => itm.topClassId !== topClassId
                        )
                        if (isParent) {
                            newArr.push(obj)
                        }
                    }

                    newArr.forEach(its => {
                        if (
                            its.materialClassId ===
                            item.materialClassId.split('/')[0]
                        ) {
                            its.children.push({
                                uuid: getUuid(),
                                customId: getUuid(),
                                acceptanceAmount: item.acceptanceAmount, // 验收金额
                                acceptanceDtlId: item.dtlId, //物资验收明细Id
                                acceptancePrice: item.price, // 验收单价
                                acceptanceTaxAmount: item.taxAmount, // 验收税额
                                apportionedFreight: '', //分摊运费
                                apportionedFreightTaxAmount: '', //分摊运费税额
                                billId: this.billid, //	采购结算id
                                changeType: 1, //变更类型
                                difference: '', // 差额
                                dtlId: item.dtlId, //采购结算明细id
                                materialClassId: item.materialClassId
                                    .split('/')
                                    .slice(1)
                                    .join('/'), //物资类别id
                                materialClassName: item.materialClassName
                                    .split('/')
                                    .slice(1)
                                    .join('/'), // 物资类别名称
                                materialId: item.materialId, //物资id
                                materialName: item.materialName, //物资名称
                                settledAmount: '', // 结算金额
                                settledPrice: '', //结算单价
                                settledQuantity: item.unsettledQuantity, //结算数量
                                sourceDtlId: item.sourceDtlId, //合同明细id
                                sourcePurchaseSettlementDtlId: '', // 原采购结算明细id
                                spec: item.spec, // 规格型号
                                taxDifference: '', // 税额差额
                                texture: item.texture, // 材质
                                unit: item.unit, //计量单位
                                unsettledQuantity: item.unsettledQuantity, // 未结算数量
                                warehouseId: item.warehouseId, //仓库id
                                warehouseName: item.warehouseName, //仓库名称
                                parentId: its.topClassId // 前端自存字段,不需要传到后端的,作用是需要一个和父级相关联的id,在全选时方便找到对应父级
                            })
                        }
                        // 统计小计
                        const count = its.children
                            .reduce(
                                (prev, c) => (prev += +c.settledAmount || 0),
                                0
                            )
                            .toFixed(2)
                        its.materialName = `金额小计： ${count}`
                    })
                }
            })
            return newArr
        },
        // 如果结算明细的原数组中有数据,需要做判断是否能再次添加数据
        settlementPush (res) {
            let newArr = this.settlementFun(res)
            newArr.forEach(item => {
                const topClassIdRp = this.wzlbTableData.every(
                    itm => itm.topClassId != item.topClassId
                )
                // 遍历当前选择数据的每一项父级id是否存在于原有数组中,如果没有,则直接添加
                if (topClassIdRp) {
                    this.wzlbTableData.push(item)
                } else {
                    // 如果数组中的父级id一样,则返回一样的那一项的父级数据
                    const target = this.wzlbTableData.find(
                        its => its.topClassId == item.topClassId
                    )
                    // 给这条父级数据的children里面添加子级
                    item.children.forEach(it => {
                        // =========相同物资id,但是验收明细id不一样时直接添加,如果物资id一样,验收明细id一样,还需要看changType是否为-1==========
                        // 如果当前父级的子级中没有验收明细id相同的,则直接添加
                        const materialIdRp = target.children.every(
                            _it => _it.acceptanceDtlId != it.acceptanceDtlId
                        )
                        if (materialIdRp) {
                            target.children.push(it)
                        } else {
                            // ==================相同物资id,但是changType为-1时======================
                            // 遍历出所有子级id一样的
                            const _target = target.children.filter(
                                i => i.acceptanceDtlId == it.acceptanceDtlId
                            )
                            // 如果当前遍历的子项存在于原数组,但是changeTpye等于-1说明已经删除,那还是可以重新添加进入的,changeType不等于-1的,不做操作;如果遍历完了都是等于-1的,才添加
                            const noPush = _target.some(
                                _i => _i.changeType !== -1
                            )
                            if (!noPush) {
                                target.children.push(it)
                            }
                        }
                    })
                }
            })
        },

        // 业务类型变化
        businessTypeChange () {
            this.formData.settlementUnitName = ''
            this.formData.settlementUnitId = ''
            this.formData.sourceBillNo = ''
            this.formData.sourceBillId = ''
            this.formData.acceptanceBillId = ''
            this.formData.acceptanceBillNo = ''
            this.formData.currency = ''
            this.formData.currencyId = ''
            this.formData.baseCurName = ''
            this.formData.baseCurId = ''
            this.formData.taxRate = ''
            this.formData.baseCurRate = ''
            this.formData.taxRate = ''
            this.formData.rmbRate = ''
            this.isEndSettle = 0 // 是否终期结算(0:否;1:是)
            this.isOffsetAdvancePayment = 0 // 是否冲预付款
            this.isPersonalBorrowing = 0 // 是否冲个人借资
            this.formData.offsetAdvancePayment = '' // 冲预付款金额(元)
            this.formData.personalBorrowing = '' // 冲个人借资金额
            this.formData.reversalObjectId = '' // 冲销对象id
            this.formData.reversalObjectNumber = '' // 冲销对象
            this.formData.borrowerId = '' // 借支人员id
            this.formData.borrowerName = '' // 借支人员
            this.formData.unoffsetAdvancePayment = '' // 未冲预付款金额
            // if (e == 2 || e == 3) {
            //     this.formData.isPersonalBorrowing = false
            //     this.formData.personalBorrowing = 0
            //     this.formData.reversalObjectNumber = ''
            //     this.formData.reversalObjectId = ''
            //     this.formData.borrowerName = ''
            //     this.formData.borrowerId = ''
            // }
            this.jgdwChange()
        },
        // 如果业务类型变化或者选择的是不同合同,需对原有基本信息和结算明细进行处理
        jgdwChange () {
            for (let i = 0; i < this.wzlbTableData.length; i++) {
                for (
                    let m = 0;
                    m < this.wzlbTableData[i]['children'].length;
                    m++
                ) {
                    if (this.wzlbTableData[i]['children'][m]['dtlId']) {
                        this.$set(
                            this.wzlbTableData[i]['children'][m],
                            'changeType',
                            -1
                        )
                        this.$set(
                            this.wzlbTableData[i]['children'][m],
                            'settledAmount',
                            0
                        )
                        this.$set(
                            this.wzlbTableData[i]['children'][m],
                            'taxDifference',
                            0
                        )
                        this.$set(
                            this.wzlbTableData[i]['children'][m],
                            'acceptanceTaxAmount',
                            0
                        )
                    } else {
                        this.wzlbTableData[i]['children'].splice(m, 1)
                        m--
                    }
                }
            }
            this.formData.acceptanceAmount = 0
            this.settlementDeleteData.push(...this.wzlbTableData)
            // 服务费用也需要清空
            for (let i = 0; i < this.serviceFeeData.length; i++) {
                if (this.serviceFeeData[i]['dtlId']) {
                    this.$set(
                        this.serviceFeeData[i],
                        'changeType',
                        -1
                    )
                    this.$set(
                        this.serviceFeeData[i],
                        'totalAmount',
                        0
                    )
                    this.$set(
                        this.serviceFeeData[i],
                        'amount',
                        0
                    )
                } else {
                    this.serviceFeeData.splice(i, 1)
                    i--
                }
            }
        },
        // 本位币汇率失去焦点时
        baseCurRateBlur () {
            if (this.formData.baseCurRate == 0) {
                this.formData.baseCurRate = null
            }
            this.formData.baseCurAmount =
                +this.formData.amount * +this.formData.baseCurRate
        },

        tableRowClassNameJS ({ row }) {
            if (row.changeType === -1) {
                return 'warning-row'
            }
            if (row.children) {
                if (row.children.length < 1) {
                    return 'warning-row'
                } else {
                    let isDel = row.children.every(it => it.changeType === -1)
                    if (isDel) {
                        return 'warning-row'
                    }
                }
            }
        },

        //明细数据汇总方法
        uniqueArray (arr, key) {
            const map = new Map()
            return arr.filter(item => {
                const val = item[key] + '' || getUuid()
                return !map.has(val) && map.set(val, 1)
            })
        },
        //我的方法 ↑

        // initData () {
        //     this.getCurrentUnitInfo()
        //     this.getTurnoverCentralizedPurchaseSummaryGetAgencyListByBillId()
        //     this.getBasicData()
        //     this.getTurnoverCentralizedPurchaseSummaryGetSummarySetting() //回去物资汇总明细
        // },
        //获取按钮状态
        getCurrentUnitInfo () {
            publicRequest.getCurrentUnitInfo(this.auditParams).then(res => {
                this.auditState = res
            })
        },
        //根据周材集采汇总id查询申报机构
        getTurnoverCentralizedPurchaseSummaryGetAgencyListByBillId () {
            planRequest
                .turnoverCentralizedPurchaseSummaryGetAgencyListByBillId(
                    this.billId
                )
                .then(res => {
                    this.OrgtableData = res
                    // this.rollUp(res)
                })
        },

        //根据周材集采汇总id查询申报机构
        getTurnoverCentralizedPurchaseSummaryGetSummarySetting () {
            planRequest
                .turnoverCentralizedPurchaseSummaryGetSummarySetting(
                    this.billId
                )
                .then(res => {
                    console.log(res, '当前打印')
                    // this.OrgtableData = res
                    this.notSetData = JSON.parse(JSON.stringify(res)) //没去重之前的数据
                    //去重
                    let children = []
                    res.forEach(item => {
                        item.children.forEach(a => {
                            children.push(a)
                        })
                    })
                    var result = []
                    var obj = {}
                    for (var i = 0; i < children.length; i++) {
                        if (children[i].materialId in obj) {
                            // 相同时肯定不push
                            if (
                                obj[children[i].materialId] !==
                                children[i].texture
                            ) {
                                // 不相同时，判断是否是 '' 和 null，如果是，则表示重复
                                if (
                                    !(
                                        !obj[children[i].materialId] &&
                                        !children[i].texture
                                    )
                                ) {
                                    // 当都不是 '' 和 null 时，才表示不重复，此时才push
                                    result.push(children[i])
                                }
                            }
                        } else {
                            obj[children[i].materialId] = children[i].texture
                            result.push(children[i])
                        }
                        // obj[children[i].amount] = 1
                    }
                    res.forEach(item => {
                        item.uuid = getUuid()

                        item.materialClassName = item.topClassName
                        item.children = result
                        item.children.forEach(v => {
                            v.uuid = getUuid()
                            v.parentId = item.uuid
                        })
                    })
                    console.log(result, 'datadata')
                    this.materialsTableData = res
                })
        },

        //点击图标的时候 获取历史记录
        clickIcon (dtlId, column) {
            this.setHistoryTableData([])
            planRequest
                .turnoverAnnualDemandPlanGetHistoryList(
                    dtlId,
                    column,
                    this.auditParams.billType
                )
                .then(res => {
                    this.historyTableData = res
                    this.setHistoryTableData(res)
                })
        },
        // 编辑的时候造历史修改数据结构
        createHistory (row, e) {
            if (row.dtlId) {
                this.createHistoryData.push({
                    historyId: '',
                    modifedName: '',
                    modifiedDate: '',
                    modifiedId: '',
                    opinion: '',
                    sourceId: row.dtlId,
                    sourceValue: 0,
                    updateColumn: e, //修改字段
                    updatedValue: row[e] //修改后的值
                })
            }
        },
        // 获取累计结算金额
        async getCurrentTotalAmount () {
            // 计算累计结算金额
            const res = await auditRequest.getCurrentTotalAmount({ sourceBillId: this.formData.sourceBillId })
            if (typeof res === 'object') {
                this.currentTotalAmount = 0
            } else {
                this.currentTotalAmount = res
            }
        },
        /**
         * 下边几个按钮
         */

        //保存按钮
        async submit () {
            // this.setSelectedInfo(this.wzlbTableData)
            // // 客户端弹窗预览结果
            // // 参数依次为: 打开页面地址、标题、回调函数
            // openAppClient('/showSelectedData', '选择结果', function () {
            //     // alert('关闭后回调')
            // })

            this.formData.amount = this.jiesuanjine - 0
            this.formData.freight = this.yunshufuwufeiyong - 0
            // this.formData.taxAmount = this.shuie - 0
            this.formData.taxAmount = this.formData.taxAmount - 0

            //  shuijiaheji () {
            // // totalAmount
            this.formData.totalAmount = this.shuijiaheji - 0
            this.formData.taxDifference = +this.taxDifferenceFun
            // 是否冲预付款
            this.isOffsetAdvancePayment == true
                ? (this.formData.isOffsetAdvancePayment = 1)
                : (this.formData.isOffsetAdvancePayment = 0)
            // 是否冲个人借支
            this.isPersonalBorrowing == true
                ? (this.formData.isPersonalBorrowing = 1)
                : (this.formData.isPersonalBorrowing = 0)
            // 是否终期结算
            this.isEndSettle == true
                ? (this.formData.isEndSettle = 1)
                : (this.formData.isEndSettle = 0)
            let count = 0
            this.formData.difference = this.wzlbTableData.forEach(item => {
                count += item.children.reduce((prev, c) => {
                    console.log(c)
                    return prev += (+c.difference || 0)
                }, 0)
            })
            this.formData.difference = +(+count).toFixed(2)
            console.log(this.formData.difference)
            await this.getCurrentTotalAmount()
            this.formData.currentTotalAmount = +(+this.currentTotalAmount + +this.formData.totalAmount).toFixed(2)
            this.$refs.rulesBase.validate(valid => {
                if (valid) {
                    this.thesubimt1()
                } else {
                    return false
                }
            })
        },
        async thesubimt1 () {
            showLoading()

            await auditRequest.updatajibenxinxi(this.formData)
            // data = this.billId
            this.theData = this.billId

            //更新明细 ↓
            if (this.wzlbTableData.length > 0) {
                for (let i = 0; i < this.wzlbTableData.length; i++) {
                    if (this.wzlbTableData[i].children.length > 0) {
                        for (
                            let j = 0;
                            j < this.wzlbTableData[i].children.length;
                            j++
                        ) {
                            this.wzlbTableData[i].children[j].billId =
                                this.billId
                            if (
                                this.wzlbTableData[i].children[j].changeType !=
                                -1
                            ) {
                                if (
                                    this.wzlbTableData[i].children[j]
                                        .changeType != null
                                ) {
                                    this.wzlbTableData[i].children[
                                        j
                                    ].changeType = 1
                                } else {
                                    this.wzlbTableData[i].children[
                                        j
                                    ].changeType = 2
                                }
                            }
                        }
                    }
                }
            }

            await auditRequest.updatemingxi(this.wzlbTableData)
            await this.getSettlement()
            //更新明细 ↑

            //更新服务费用 ↓
            if (this.serviceFeeData.length > 0) {
                for (let i = 0; i < this.serviceFeeData.length; i++) {
                    this.serviceFeeData[i].billId = this.billId
                    if (this.serviceFeeData[i].changeType != -1) {
                        if (this.serviceFeeData[i].changeType != null) {
                            this.serviceFeeData[i].changeType = 1
                        } else {
                            this.serviceFeeData[i].changeType = 2
                        }
                    }
                }
            }
            await auditRequest.updatefuwufeiyong(this.serviceFeeData)
            await this.getServiceFee()
            //更新服务费用 ↑

            //更新暂扣保证金 ↓
            if (this.zkbzjtableData.length > 0) {
                for (let i = 0; i < this.zkbzjtableData.length; i++) {
                    this.zkbzjtableData[i].billId = this.billId
                    this.zkbzjtableData[i].returnDepositType = 1
                    if (this.zkbzjtableData[i].changeType != -1) {
                        if (this.zkbzjtableData[i].changeType != null) {
                            this.zkbzjtableData[i].changeType = 1
                        } else {
                            this.zkbzjtableData[i].changeType = 2
                        }
                    }
                }
            }
            await auditRequest.updatebzj(this.zkbzjtableData)

            //更新暂扣保证金 ↑

            //更新返还保证金 ↓
            if (this.fhbzjtableData.length > 0) {
                for (let i = 0; i < this.fhbzjtableData.length; i++) {
                    this.fhbzjtableData[i].billId = this.billId
                    this.fhbzjtableData[i].returnDepositType = 2
                    if (this.fhbzjtableData[i].changeType != -1) {
                        // if(this.Thewas == 'add') {
                        //     this.fhbzjtableData[i].changeType = 1
                        // }else{
                        //     this.fhbzjtableData[i].changeType = 2
                        // }
                    }
                }
            }
            await auditRequest.updatebzj(this.fhbzjtableData)
            await this.getMargin()
            //更新返回保证金 ↑
            hideLoading()
            this.clientPop('suc', '保存成功')
            // this.$router.replace('/materialProcurementList')
        },

        // 保存并提交
        async submitCommit () {
            // this.setSelectedInfo(this.wzlbTableData)
            // // 客户端弹窗预览结果
            // // 参数依次为: 打开页面地址、标题、回调函数
            // openAppClient('/showSelectedData', '选择结果', function () {
            //     // alert('关闭后回调')
            // })
            // this. thetijiao2()

            this.formData.amount = this.jiesuanjine - 0
            this.formData.freight = this.yunshufuwufeiyong - 0
            // this.formData.taxAmount = this.shuie - 0
            this.formData.taxAmount = this.formData.taxAmount - 0
            this.formData.totalAmount = this.shuijiaheji - 0
            this.formData.taxDifference = +this.taxDifferenceFun
            // 是否冲预付款
            this.isOffsetAdvancePayment == true
                ? (this.formData.isOffsetAdvancePayment = 1)
                : (this.formData.isOffsetAdvancePayment = 0)
            // 是否冲个人借支
            this.isPersonalBorrowing == true
                ? (this.formData.isPersonalBorrowing = 1)
                : (this.formData.isPersonalBorrowing = 0)
            // 是否终期结算
            this.isEndSettle == true
                ? (this.formData.isEndSettle = 1)
                : (this.formData.isEndSettle = 0)
            // 计算差额
            let count = 0
            this.formData.difference = this.wzlbTableData.forEach(item => {
                count += item.children.reduce((prev, c) => {
                    console.log(c)
                    return prev += (+c.difference || 0)
                }, 0)
            })
            this.formData.difference = +(+count).toFixed(2)
            // 计算截止本期末累计结算金额
            await this.getCurrentTotalAmount()
            this.formData.currentTotalAmount = +(+this.currentTotalAmount + +this.formData.totalAmount).toFixed(2)
            this.$refs.rulesBase.validate(valid => {
                if (valid) {
                    this.thetijiao2()
                } else {
                    return false
                }
            })
        },
        async thetijiao2 () {

            await auditRequest.updatajibenxinxi(this.formData)
            // data = this.billId
            this.theData = this.billId

            //更新明细 ↓
            if (this.wzlbTableData.length > 0) {
                for (let i = 0; i < this.wzlbTableData.length; i++) {
                    if (this.wzlbTableData[i].children.length > 0) {
                        for (
                            let j = 0;
                            j < this.wzlbTableData[i].children.length;
                            j++
                        ) {
                            this.wzlbTableData[i].children[j].billId =
                                this.billId
                            if (
                                this.wzlbTableData[i].children[j].changeType !=
                                -1
                            ) {
                                if (
                                    this.wzlbTableData[i].children[j]
                                        .changeType != null
                                ) {
                                    this.wzlbTableData[i].children[
                                        j
                                    ].changeType = 1
                                } else {
                                    this.wzlbTableData[i].children[
                                        j
                                    ].changeType = 2
                                }
                            }
                        }
                    }
                }
            }
            // this.setSelectedInfo(this.wzlbTableData)
            // openAppClient('/showSelectedData', '选择结果')
            await auditRequest.updatemingxi(this.wzlbTableData)
            //更新明细 ↑

            //更新服务费用 ↓
            if (this.serviceFeeData.length > 0) {
                for (let i = 0; i < this.serviceFeeData.length; i++) {
                    this.serviceFeeData[i].billId = this.billId
                    if (this.serviceFeeData[i].changeType != -1) {
                        if (this.serviceFeeData[i].changeType != null) {
                            this.serviceFeeData[i].changeType = 1
                        } else {
                            this.serviceFeeData[i].changeType = 2
                        }
                    }
                }
            }
            await auditRequest.updatefuwufeiyong(this.serviceFeeData)
            //更新服务费用 ↑

            //更新暂扣保证金 ↓
            if (this.zkbzjtableData.length > 0) {
                for (let i = 0; i < this.zkbzjtableData.length; i++) {
                    this.zkbzjtableData[i].billId = this.billId
                    this.zkbzjtableData[i].returnDepositType = 1
                    if (this.zkbzjtableData[i].changeType != -1) {
                        if (this.zkbzjtableData[i].changeType != null) {
                            this.zkbzjtableData[i].changeType = 1
                        } else {
                            this.zkbzjtableData[i].changeType = 2
                        }
                    }
                }
            }
            await auditRequest.updatebzj(this.zkbzjtableData)
            //更新暂扣保证金 ↑

            //更新返还保证金 ↓
            if (this.fhbzjtableData.length > 0) {
                for (let i = 0; i < this.fhbzjtableData.length; i++) {
                    this.fhbzjtableData[i].billId = this.billId
                    this.fhbzjtableData[i].returnDepositType = 2
                    if (this.fhbzjtableData[i].changeType != -1) {
                        // if(this.Thewas == 'add') {
                        //     this.fhbzjtableData[i].changeType = 1
                        // }else{
                        //     this.fhbzjtableData[i].changeType = 2
                        // }
                    }
                }
            }
            await auditRequest.updatebzj(this.fhbzjtableData)
            // 如果业务类型选择的是物资采购合同,在提交审核前,需要检测是否做了动态评价,已做动态评价才可提交审核操作
            if (this.formData.businessType === 1) {
                if (!this.formData.evaluationLevel) {
                    this.clientPop(
                        'err',
                        '合同类结算需先做动态评价后才能提交审核',
                        this.handleClose
                    )
                    return
                }
            }
            // 需要验证基本信息中税价合计和服务费用两者不能同时为0
            if (this.formData.totalAmount == 0 && this.formData.freight == 0) {
                this.clientPop('err', '税价合计和服务费用，两者不可同时为0。')
                return
            }
            // 如果没有勾选冲预付款并且存在剩余预付款金额
            if (!this.isOffsetAdvancePayment && +this.formData.unoffsetAdvancePayment) {
                this.clientPop(
                    'info',
                    `剩余${this.formData.unoffsetAdvancePayment}预付款还未冲销，是否冲预付款？`,
                    async () => {
                        try{
                            showLoading()
                            // 如果勾选是,那就需要让是否冲预付款的复选框勾选上,并且把剩余预付款赋值给对应字段
                            this.isOffsetAdvancePayment = true
                            this.formData.offsetAdvancePayment = this.formData.unoffsetAdvancePayment
                            await auditRequest.updatajibenxinxi(this.formData)
                            await publicReques.commitexamine({
                                billId: this.billId,
                                billType: '1020'
                            })
                            this.clientPop('suc', '提交成功')
                            this.$router.replace('/materialProcurementList')
                        }finally{
                            hideLoading()
                        }
                    },
                    null,
                    async ()=> {
                        try{
                            showLoading()
                            await publicReques.commitexamine({
                                billId: this.billId,
                                billType: '1020'
                            })
                            this.clientPop('suc', '提交成功')
                            this.$router.replace('/materialProcurementList')
                        }finally{
                            hideLoading()
                        }

                    }
                )
            } else {
                await publicReques.commitexamine({
                    billId: this.billId,
                    billType: '1020'
                })
                this.clientPop('suc', '提交成功')
                this.$router.replace('/materialProcurementList')
            }
        },
        //计划明细非空验证
        verifyTable () {
            this.errorMsg = []
            if (this.OrgtableData.length > 0) {
                this.OrgtableData.forEach((n, index) => {
                    if (n.dtls) {
                        n.dtls.forEach(v => {
                            v.children.forEach(item => {
                                if (item.changeType !== -1) {
                                    if (
                                        item.approvalQuantity == '' ||
                                        item.approvalQuantity == null
                                    ) {
                                        let str = `请填写第 ${
                                            index + 1
                                        } 行的核准数量`
                                        this.errorMsg.push(str)
                                    }
                                    if (
                                        item.approvalPrice == '' ||
                                        item.approvalPrice == null
                                    ) {
                                        let str = `请填写第 ${
                                            index + 1
                                        } 行的核准单价`
                                        this.errorMsg.push(str)
                                    }
                                }
                            })
                        })
                    }
                })
            }

            if (this.errorMsg.length > 0) {
                this.isErrorMsg = true
            } else {
                this.isErrorMsg = false
            }
        },
        // nullify () {
        //     //作废
        //     this.setAuditParams(this.nullifyParams)
        //     // 客户端弹窗弹出本地页面
        //     openAppClient('/nullifyDialog', '单据作废原因', () => {
        //         const auditParams = JSON.parse(
        //             localStorage.vuex
        //         ).auditParams
        //         auditRequest.nullify(auditParams).then(() => {
        //             this.clientPop('suc', '作废成功')
        //             this.getCurrentUnitInfo()
        //         })
        //     })
        // },
        //把子列表的数据合并到this.OrgtableData的children
        DoMaterialsTableData () {
            this.OrgtableData.forEach(item => {
                item.changeType = 1
                item.billId = this.billId
            })
        },
        async baocunyanzheng () {
            this.formData.amount = this.jiesuanjine - 0
            this.formData.freight = this.yunshufuwufeiyong - 0
            // this.formData.taxAmount = this.shuie - 0
            this.formData.taxAmount = this.formData.taxAmount - 0
            //  shuijiaheji () {
            // // totalAmount
            this.formData.totalAmount = this.shuijiaheji - 0
            this.formData.taxDifference = +this.taxDifferenceFun

            this.formData.isOffsetAdvancePayment == true
                ? (this.formData.isOffsetAdvancePayment = 1)
                : (this.formData.isOffsetAdvancePayment = 0)

            this.formData.isPersonalBorrowing == true
                ? (this.formData.isPersonalBorrowing = 1)
                : (this.formData.isPersonalBorrowing = 0)

            await auditRequest.updatajibenxinxi(this.formData)
            // data = this.billId
            this.theData = this.billId

            if (this.wzlbTableData.length > 0) {
                for (let i = 0; i < this.wzlbTableData.length; i++) {
                    if (this.wzlbTableData[i].children.length > 0) {
                        for (
                            let j = 0;
                            j < this.wzlbTableData[i].children.length;
                            j++
                        ) {
                            this.wzlbTableData[i].children[j].billId =
                                this.billId
                            if (
                                this.wzlbTableData[i].children[j].changeType !=
                                -1
                            ) {
                                if (
                                    this.wzlbTableData[i].children[j]
                                        .changeType != null
                                ) {
                                    this.wzlbTableData[i].children[
                                        j
                                    ].changeType = 1
                                } else {
                                    this.wzlbTableData[i].children[
                                        j
                                    ].changeType = 2
                                }
                            }
                        }
                    }
                }
            }
            await auditRequest.updatemingxi(this.wzlbTableData)

            if (this.serviceFeeData.length > 0) {
                for (let i = 0; i < this.serviceFeeData.length; i++) {
                    this.serviceFeeData[i].billId = this.billId
                    if (this.serviceFeeData[i].changeType != -1) {
                        if (this.serviceFeeData[i].changeType != null) {
                            this.serviceFeeData[i].changeType = 1
                        } else {
                            this.serviceFeeData[i].changeType = 2
                        }
                    }
                }
            }
            await auditRequest.updatefuwufeiyong(this.serviceFeeData)

            if (this.zkbzjtableData.length > 0) {
                for (let i = 0; i < this.zkbzjtableData.length; i++) {
                    this.zkbzjtableData[i].billId = this.billId
                    this.zkbzjtableData[i].returnDepositType = 1
                    if (this.zkbzjtableData[i].changeType != -1) {
                        if (this.zkbzjtableData[i].changeType != null) {
                            this.zkbzjtableData[i].changeType = 1
                        } else {
                            this.zkbzjtableData[i].changeType = 2
                        }
                    }
                }
            }
            await auditRequest.updatebzj(this.zkbzjtableData)

            if (this.fhbzjtableData.length > 0) {
                for (let i = 0; i < this.fhbzjtableData.length; i++) {
                    this.fhbzjtableData[i].billId = this.billId
                    this.fhbzjtableData[i].returnDepositType = 2
                    if (this.fhbzjtableData[i].changeType != -1) {
                        // if(this.Thewas == 'add') {
                        //     this.fhbzjtableData[i].changeType = 1
                        // }else{
                        //     this.fhbzjtableData[i].changeType = 2
                        // }
                    }
                }
            }
        },
        //点击选择 选择申报单位 获取申报机构
        selectUnit () {
            planRequest
                .turnoverCentralizedPurchaseSummaryGetAgencyListByOrgId([
                    '1505122036192309249'
                ])
                .then(res => {
                    this.OrgtableData = res
                    this.DoMaterialsTableData() //给数据造billid 和 chengetype
                    this.isCollect = true
                })
        },
        //点击申报单位列表点击编号显示对应子列表
        tableDbShow (row, column) {
            row.dtls = []
            if (column.label === '年度需用计划编号') {
                if (row.changeType == 1) {
                    planRequest
                        .turnoverCentralizedPurchaseSummaryGetAllMaterial(
                            row.annualDemandPlanBillId
                        )
                        .then(res => {
                            this.OrgSonTableData = res
                            this.OrgSonTableData.forEach(item => {
                                item.changeType = 1
                                item.uuid = getUuid()
                                item.materialClassName = item.topClassName

                                item.children.forEach(v => {
                                    v.changeType = 1
                                    v.parentId = item.uuid
                                    v.uuid = getUuid()
                                })
                                row.dtls.push(item)
                            })
                        })
                } else {
                    planRequest
                        .turnoverCentralizedPurchaseSummaryGetMaterial(
                            row.dtlId
                        )
                        .then(res => {
                            this.OrgSonTableData = res
                            this.OrgSonTableData.forEach(item => {
                                item.uuid = getUuid()
                                item.materialClassName = item.topClassName
                                row.dtls.push(item)
                                item.children.forEach(v => {
                                    v.changeType = 2
                                    v.parentId = item.uuid
                                    v.uuid = getUuid()
                                })
                            })
                        })
                }
            }
        },
        // 点击子表的选择明细
        selectDetails () {
            console.log('选择明细')
        },
        //点击集中采购单位 选择单位

        // clickPurchasingUnit (row) {
        //     selectDataClient()
        //     // 弹窗选择数据
        //     selectDataClient({
        //         SelectServiceToken: '/hr/org/getChildrenOrg', // 客户端对应方法名
        //         IsSingleMode: true, // 是否单选 true 单选 false 多选
        //         SelectedIDs: [], // 已选中id
        //         Title: '选择全集团组织机构数据', // 标题
        //         InitParamsStr: JSON.stringify({ orgId: this.basicFormData.orgId }), //参数

        //     }).then(val => {
        //         const orgData = val[0] //获取客户端返回的数据
        //         row.purchasingUnitId = orgData.orgId
        //         row.purchasingUnitName = orgData.orgName
        //         row.changeType === 1 ? this.count_(row, 1) : this.count_(row, 2) //判断当前的状态是新增还是修改
        //         // 保存用户选择返回数据到store
        //         this.setSelectedInfo(val)
        //         // 客户端弹窗预览结果
        //         // 参数依次为: 打开页面地址、标题、回调函数
        //         // openAppClient('/showSelectedData', '选择结果', function () {
        //         //     alert('关闭后回调')

        //         // })
        //     })
        // },
        //点击物资汇总的物资名称，汇总物资下的所有机构
        showA (row) {
            console.log(row, 'row')
            console.log(this.notSetData, 'this.notSetData')
            this.materialsNameData = []
            this.notSetData.forEach(item => {
                item.children.forEach(b => {
                    if (row.materialId === b.materialId) {
                        // const obj = {
                        //     orgName: item.orgName,
                        //     materialName: b.materialName,
                        //     spec: b.spec,
                        //     unit: b.unit,
                        //     texture: b.texture,
                        //     planQuantity: b.planQuantity,
                        //     marketPrice: '',
                        //     amount: b.amount
                        // }
                        // this.materialsNameData = []
                        this.materialsNameData.push(b)
                    }
                })
            })
        },
        //申报机构汇总-删除 申报机构汇总表格明细
        deleteMaterials () {
            if (this.planSelect.length > 0) {
                this.OrgtableData.forEach(v => {
                    this.planSelect.forEach(item => {
                        if (item.dtlId && item.dtlId === v.dtlId) {
                            v.changeType = -1
                        }
                    })
                })
            }
            if (this.planSelect.length > 0) {
                this.planSelect.forEach(item => {
                    if (item.dtlId) {
                        const newArr = []
                        newArr.push(item)
                        newArr.forEach(item => {
                            this.$set(item, 'changeType', -1)
                        })

                        // this.$refs.multipleTable.clearSelection()
                    } else {
                        const localArr = []
                        localArr.push(item)
                        for (let i = this.OrgtableData.length; i > 0; i--) {
                            for (let j = 0; j < localArr.length; j++) {
                                if (this.OrgtableData[i - 1] === localArr[j]) {
                                    this.OrgtableData.splice(i - 1, 1)
                                }
                            }
                        }
                        // this.$refs.multipleTable.clearSelection()
                    }
                })
            }
            console.log(this.OrgtableData)
        },

        // //监听明细 机构汇总表格 数据input事件 判断用户是否修改  ，计算金额
        // countInput (row) {
        //     row.changeType === 1 ? this.count_(row, 1) : this.count_(row, 2)
        //     console.log(this.materialsTableData, '物资汇总')
        // },
        // // 汇总逻辑
        // count_ (row, num) {
        //     row.changeType = num
        //     this.basicFormData.amount = null

        //     row.approvalAmount =  row.approvalQuantity * row.approvalPrice
        //     this.OrgtableData.forEach(item =>{
        //         console.log(item, '逻辑汇总')
        //         item.changeType = num
        //         this.basicFormData.amount += item.totalAmount = row.approvalAmount  //把汇总的金额给父级 方便汇总计算
        //         if(item.children) {
        //             item.children.forEach(i=>{
        //                 i.changeType = num
        //             })
        //         }
        //     })
        // },
        //申报机构汇总-明细子列表删除按钮
        deleteEle (row) {
            row.changeType = -1
            this.OrgtableData.forEach(item => {
                item.changeType = 2
                if (item.dtls) {
                    item.dtls.forEach(v => {
                        if (v.children) {
                            const data = v.children.find(i => {
                                return i.dtlId === row.dtlId
                            })
                            data.changeType = -1
                        }
                    })
                }
            })
        },

        //删除提示框
        ctDelete () {
            showPromptPop(
                '确定要删除吗？删除的数据可以在【回收站】还原或彻底删除。'
            )
        },
        //根据集采汇总id删除单据
        delData () {
            planRequest
                .turnoverCentralizedPurchaseSummaryDelete(this.billId)
                .then(res => {
                    if (res.code == 200) {
                        showSuccessPop('删除成功！')
                        this.isSkip = true
                    }
                    this.$router.push('./revolveCollectList')
                })
        },
        handleFullScreen () {
            this.fullscreen = !this.fullscreen
        },
        //查询附件信息
        getAttach () {
            this.objFlag.flag5 = true
        },
        tableRowClassName ({ row }) {
            if (row.changeType === -1) {
                return 'warning-row'
            }
            return ''
        },
        // 结算明细里面的全选
        settlementSelectAll (selection) {
            this.settlementSelects = !this.settlementSelects

            this.splite(this.wzlbTableData, this.settlementSelects)

            // 如果点击全选后,选中数据的长度和原始数组中父级加上changeType不等于-1的子级数据总数相等,就说明是全选选中,否则是全不选中
            let count = 0
            this.wzlbTableData.forEach(item => {
                count++
                item.children.forEach(it => {
                    if (it.changeType !== -1) {
                        count++
                    }
                })
            })
            // console.log(count)
            let num = 0
            selection.forEach(item => {
                if (item.changeType) {
                    if (item.changeType !== -1) {
                        num++
                    }
                } else {
                    num++
                }
            })
            // console.log(selection)
            if (num === count) {
                this.settlementSelects = true
            } else {
                this.settlementSelects = false
            }

            // 如果全选按钮是选中状态,那么父级控制选中与否的字段isChecked就应该是true
            if (this.settlementSelects) {
                this.wzlbTableData.forEach(i => {
                    i.isChecked = true
                })
            } else {
                this.wzlbTableData.forEach(i => {
                    i.isChecked = false
                })
            }
            // 点击全选的时候,把已经删除的子级changType设置为选中,如果某个父级下面所有的子级都为-1,则需要将这个父级的isChecked设置为true
            this.wzlbTableData.forEach(item => {
                item.children.forEach(it => {
                    if (it.changeType === -1) {
                        this.$refs.multipleTable1.toggleRowSelection(it, true)
                    }
                })
                let isCheckedAllChildren = item.children.every(
                    its => its.changeType === -1
                )
                if (isCheckedAllChildren) {
                    this.$refs.multipleTable1.toggleRowSelection(item, true)
                    item.isChecked = true
                }
            })
            console.log(this.wzlbTableData)
        },
        splite (data, flag) {
            data.forEach(row => {
                this.$refs.multipleTable1.toggleRowSelection(row, flag)
                if (row.children != undefined) {
                    this.splite(row.children, flag)
                }
            })
        },
        // 当用户手动勾选数据行的 Checkbox 时触发的事件
        selectRow (selection, row) {
            if (row.children) {
                if (row.isChecked) {
                    row.children.forEach(item => {
                        if (item.changeType !== -1) {
                            this.$refs.multipleTable1.toggleRowSelection(
                                item,
                                false
                            )
                        }
                    })
                    row.isChecked = false
                } else {
                    row.children.forEach(item => {
                        if (item.changeType !== -1) {
                            this.$refs.multipleTable1.toggleRowSelection(
                                item,
                                true
                            )
                        }
                    })
                    row.isChecked = true
                    console.log(this.wzlbTableData)
                }
            } else {
                const _parentId = row.parentId
                let count = 0
                const target = this.wzlbTableData.find(i => {
                    if (i.topClassId === _parentId) {
                        i.children.forEach(its => {
                            if (its.changeType !== -1) {
                                count++
                            }
                        })
                        return i
                    }
                })
                console.log(count)
                console.log(selection)
                const _target = selection.filter(it => {
                    return it.parentId === _parentId && it.changeType !== -1
                })
                console.log(_target)

                if (count === _target.length) {
                    this.$refs.multipleTable1.toggleRowSelection(target, true)
                    target.isChecked = true
                } else {
                    this.$refs.multipleTable1.toggleRowSelection(target, false)
                    target.isChecked = false
                }
            }

            // // 全选判断
            const isAll = this.wzlbTableData.every(i => {
                return i.isChecked === true
            })
            console.log(this.wzlbTableData)
            console.log(isAll)
            if (isAll) {
                this.tableHeadClass = 'tableHeadClass'
                this.settlementSelects = true
            } else {
                this.tableHeadClass = 'cancelClass'
                this.settlementSelects = false
            }
            // console.log(selection)
        },

        //获取用户在 汇总明细-申报机构汇总 表格的已选择项
        planTableSelect () {
            this.planSelect = this.$refs.multipleTable1.selection
            this.planSelect = this.planSelect.filter(item => {
                if (item.children) {
                    const isEmpty = item.children.every(i => {
                        return i.changeType === -1
                    })
                    return isEmpty ? false : true
                } else {
                    return item.changeType !== -1
                }
            })
        },

        planTableSelect2 (selection) {
            this.planSelect2 = selection
        },
        planTableSelect3 (selection) {
            this.planSelect3 = selection.filter(
                item => item.changeType !== -1
            )
        },
        planTableSelect4 (selection) {
            this.planSelect4 = selection.filter(
                item => item.changeType !== -1
            )
        },
        shanchumx () {
            console.log(this.wzlbTableData)
            //先判断是 选择的 自己还是
            this.clientPop(
                'info',
                '确认删除这' + this.planSelect.length + '条数据吗？',
                this.deljkk1,
                null,
                this.deljkk5
            )
        },
        shanchumx2 () {
            console.log(this.serviceFeeData)
            this.clientPop(
                'info',
                '确认删除这' + this.planSelect2.length + '条数据吗？',
                this.deljkk2,
                null,
                this.deljkk5
            )
        },
        shanchumx3 () {
            this.clientPop(
                'info',
                '确认删除这' + this.planSelect3.length + '条数据吗？',
                this.deljkk3,
                null,
                this.deljkk5
            )
        },
        shanchumx4 () {
            this.clientPop(
                'info',
                '确认删除这' + this.planSelect4.length + '条数据吗？',
                this.deljkk4,
                null,
                this.deljkk5
            )
        },
        deljkk1 () {
            for (let i = 0; i < this.wzlbTableData.length; i++) {
                for (
                    let j = 0;
                    j < this.wzlbTableData[i].children.length;
                    j++
                ) {
                    for (let h = 0; h < this.planSelect.length; h++) {
                        if (
                            this.wzlbTableData[i].children[j].uuid ==
                            this.planSelect[h].uuid
                        ) {
                            this.wzlbTableData[i].children[j].changeType = -1
                            this.wzlbTableData[i].children[j].settledAmount = 0
                            this.wzlbTableData[i].children[j].difference = 0
                            this.wzlbTableData[i].children[j].taxDifference = 0
                        }
                    }
                }
            }
            this.$refs.multipleTable1.clearSelection()
        },
        deljkk2 () {
            this.planSelect2.forEach(row => {
                if(row.dtlId) {
                    const index = this.serviceFeeData.findIndex(item => {
                        return item.dtlId == row.dtlId
                    })
                    this.$set(this.serviceFeeData[index], 'changeType', -1)
                    this.$set(this.serviceFeeData[index], 'amount', 0)
                    this.$set(this.serviceFeeData[index], 'totalAmount', 0)
                }else {
                    this.serviceFeeData.forEach((item, index) => {
                        if (this._.isEqual(item, row)) {
                            this.serviceFeeData.splice(index, 1)
                        }
                    })
                }
            })
            this.$refs.multipleTable2.clearSelection()
        },
        deljkk3 () {
            for (let i = 0; i < this.zkbzjtableData.length; i++) {
                for (let j = 0; j < this.planSelect3.length; j++) {
                    if (this.zkbzjtableData[i].id == this.planSelect3[j].id) {
                        this.zkbzjtableData[i].changeType = -1
                        this.zkbzjtableData[i].amount = 0
                    }
                }
            }
            this.$refs.multipleTable3.clearSelection()
        },
        deljkk4 () {
            for (let i = 0; i < this.fhbzjtableData.length; i++) {
                for (let j = 0; j < this.planSelect4.length; j++) {
                    if (this.fhbzjtableData[i].id == this.planSelect4[j].id) {
                        this.fhbzjtableData[i].changeType = -1
                    }
                }
            }
            this.$refs.multipleTable4.clearSelection()
        },
        deljkk5 () {
            console.log('没事了')
        },
        //关闭
        handleClose () {
            hideLoading()
            this.$router.replace('/materialProcurementList')
        },
        onChangeTab (e) {
            const height  = $('#' + e.name).offset().top
            $.scrollTo(height - this.topHeight, 500)
            this.clickId = e.name //记录每次点击的id
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight () {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById('evaluateCon')) {
                    const lastConHeight =
                        document.getElementById('evaluateCon').offsetHeight
                    console.log('lastConHeight: ', lastConHeight)
                    this.lastConHeight = lastConHeight
                    console.log('this.lastConHeight', this.lastConHeight)
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },
        cellClsNm ({ column }) {
            if (column.label === '') {
                return 'fixed-left'
            }
        },

        // 源单编号-跳转到对应的详情页
        sourceBillNoClick () {
            let url = ''
            let name = ''
            switch (this.formData.businessType) {
            case 0:
                url = '/sporadicPurchaseParticulars'
                name = '查看零星采购计划'
                break
            case 1:
                url = '/ctMaterialApplyShow'
                name = '查看物资采购合同'
                break
            case 2:
                url = '/interiorAllotEetails'
                name = '查看内部调拨'
                break
            }
            openAppClient(
                `${url}?billid=${this.formData.sourceBillId}&isview=${true}`,
                `${name}`
            )
        },

        // 点击验收编号,查看验收单
        acceptanceBillNoClick () {
            openAppClient(
                `/goodsCheckDetails?isview=${true}&billid=${
                    this.formData.acceptanceBillId
                }`,
                '查看物资验收'
            )
        }
    },
    watch: {
        jiesuanjine (nebbb) {
            // amount 结算金额 baseCurAmount结算金额 本位币
            this.formData.baseCurAmount = nebbb - 0
            this.formData.taxAmount = (
                (nebbb - 0) *
                (this.formData.taxRate / 100)
            ).toFixed(2)
        },
        'formData.redBillState' () {
            if (this.formData.redBillState == 3) {
                this.redBillStateStyle.backgroundColor = '#FF2300'
            } else if (
                this.formData.redBillState == 0 ||
                this.formData.redBillState == 1
            ) {
                this.redBillStateStyle.backgroundColor = '#FFA40D'
            } else if (this.formData.redBillState == 2) {
                this.redBillStateStyle.backgroundColor = 'rgb(153,153,153)'
            }
        },
        settlementSelects () {
            if (this.settlementSelects) {
                this.tableHeadClass = 'tableHeadClass'
            } else {
                this.tableHeadClass = 'cancelClass'
            }
        },
        // 监听是否勾选终期结算
        isEndSettle () {
            if(this.isEndSettle) {
                if(this.formData.unoffsetAdvancePayment) {
                    this.isOffsetAdvancePayment = true
                }else {
                    this.isOffsetAdvancePayment = false
                }
                this.formData.offsetAdvancePayment = this.formData.unoffsetAdvancePayment
                this.isTotalPrice = false
            }else {
                this.isTotalPrice = true
            }
        }

    },
    computed: {
        ...mapState({
            options: state => state.contract.ctClassify,
            popConfirm: 'popConfirm',
            popStatus: 'popStatus',
            userInfo: state => state.userInfo,
            currencyForm: state => state.equip.equipData.currencyForm, //币种
            state: state => state.equip.equipData.state //通用流程状态
        }),
        // shuiechajia(){
        //     return (this.formData.taxAmount - 0) -
        // },
        //my ↓
        shuijiaheji () {
            // totalAmount 税价合计
            // 暂扣保证金金额的和
            let count = this.zkbzjtableData.reduce((prev, c) => prev += (+c.amount || 0), 0)
            // 税价合计 = 结算金额+税额+保证金-冲预付款金额
            return +(
                +this.jiesuanjine +
                    +this.formData.taxAmount +
                    +count -
                    +this.formData.offsetAdvancePayment
            ).toFixed(2)

        },
        shuie: {
            //  taxAmount
            get () {
                // if(this.formData.taxAmount == 0) {
                if (this.jiesuanjine > 0 && this.formData.taxRate > 0) {
                    return +(
                        this.jiesuanjine *
                        (this.formData.taxRate / 100)
                    ).toFixed(2)
                } else {
                    return 0
                }
                // }else{
                //     return this.formData.taxAmount
                // }
            },
            set (nw) {
                console.log(nw)
            }
        },
        jiesuanjine () {
            // settledAmount金额 settledQuantity结算数量 settledPrice单价 taxDifference税额差价
            if (this.wzlbTableData.length > 0) {
                let num = 0
                for (let i = 0; i < this.wzlbTableData.length; i++) {
                    if (this.wzlbTableData[i].children.length > 0) {
                        for (
                            let j = 0;
                            j < this.wzlbTableData[i].children.length;
                            j++
                        ) {
                            num +=
                                this.wzlbTableData[i].children[j]
                                    .settledAmount - 0 || 0
                        }
                    }
                }
                return +(+num).toFixed(2)
            } else {
                return this.formData.amount || 0
            }

            // if(this.formData.amount == 0) {
            //     if(this.wzlbTableData.length > 0) {
            //         let num = 0
            //         for(let i = 0 ; i < this.wzlbTableData.length; i++) {
            //             if(this.wzlbTableData[i].children.length > 0) {
            //                 for(let j = 0 ; j < this.wzlbTableData[i].children.length; j++) {
            //                     num += (this.wzlbTableData[i].children[j].settledAmount) - 0 || 0
            //                 }
            //             }
            //         }
            //         return num
            //     }else{
            //         return 0
            //     }
            // }else{
            //     return this.formData.amount
            // }
        },
        // my ↑
        yunshufuwufeiyong () {
            // if(this.freight != 0) {
            if (this.serviceFeeData.length > 0) {
                let num = 0
                for (let i = 0; i < this.serviceFeeData.length; i++) {
                    num += +this.serviceFeeData[i].totalAmount
                }
                return num.toFixed(2)
            } else {
                return 0
            }
            // }else{
            //     return 0
            // }
        },
        // 计算基本信息的税额差额
        taxDifferenceFun () {
            let countSum = 0
            this.wzlbTableData.forEach(item => {
                let count = item.children.reduce((prev, c) => prev += (+c.taxDifference || 0), 0)
                countSum += +count
            })
            return +(+countSum).toFixed(2)
        },
        // localPopConfirm () {
        //     if (this.popConfirm) {
        //         switch (this.popStatus) {
        //         case 'prompt':
        //             this.delData()
        //             break
        //         case 'success':
        //             if (this.isSkip) this.handleClose()
        //             break
        //         }
        //         this.setPopConfirm(false)
        //     }
        //     return this.popConfirm
        // },
        judgeRoute () {
            if (this.$route.path.includes('Add')) {
                return false
            }
            return true
        },
        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 72 - this.lastConHeight
        },
        attachId () {
            return this.billId
        },

        // 红单状态
        redBillStateFun () {
            let redState = ''
            switch (this.formData.redBillState) {
            case 0:
                redState = '冲销中'
                break
            case 1:
                redState = '冲销中'
                break
            case 2:
                redState = '已冲销'
                break
            case 3:
                redState = '红单'
                break
            }
            return redState
        }
    },

    mounted () {
        // 获取最后一个内容区域的高度，计算底部空白
        this.billId = this.$route.query.billid
        this.getLastConHeight()

        // 保存所有tabName
        const arr = [
            'baseInfo',
            'planDetail',
            'fwfy',
            'bzj',
            'accessory',
            'auditHistory'
        ]
        let $idsTop = []
        window.addEventListener('scroll', () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            //当点击的tab有子tab时做滚动逻辑
            if (this.clickTabFlag && arr.find(x => x === this.clickId)) {
                this.childTabClass = '' //无子tab时清空tab的类名
                return
            }

            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    let itemTop
                    let arr
                    if (item instanceof Array) {
                        const prevHeight = document.getElementById(
                            item[0]
                        ).offsetHeight //因这里一个选项有两个表格，需获取前一个表格的高度进行计算
                        arr = item.map((x, i) => {
                            if (i === 0) {
                                return document.getElementById(x).offsetTop
                            } else {
                                return (
                                    document.getElementById(x).offsetTop +
                                    prevHeight +
                                    document.getElementById(item[0]).offsetTop
                                )
                            }
                        })
                        return arr
                    } else {
                        itemTop = document.getElementById(item).offsetTop
                        return itemTop
                    }
                })
            }
            const scrollTop =
                document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            let curLocalChild = 1
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                if ($idsTop[i] instanceof Array) {
                    let item = $idsTop[i]
                    for (let lenth = item.length, j = lenth - 1; j >= 1; j--) {
                        let itemChild = $idsTop[i][j]
                        if (scrollTop + 1 >= itemChild) {
                            curLocalChild = j
                            break
                        }
                    }
                    if (scrollTop + 1 >= item[0]) {
                        curLocal = i
                        break
                    }
                } else {
                    let item = $idsTop[i]
                    if (scrollTop + 1 >= item) {
                        curLocal = i
                        break
                    }
                }
            }
            // 设置对应tabName
            if (arr[curLocal] instanceof Array) {
                this.tabsName = arr[curLocal][0]
                this.tabsNameChild = arr[curLocal][curLocalChild]
            } else {
                this.tabsName = arr[curLocal]
            }
            // //动态改变二级选项卡类名
            // arr.forEach((item, index) => {
            //     if (item instanceof Array) {
            //         let tabNavHeight = document.querySelector('.childTab .el-tabs__nav')
            //             ? document.querySelector('.childTab .el-tabs__nav').offsetHeight
            //             : 0
            //         if (scrollTop + 1 >= $idsTop[index + 1] - tabNavHeight) {
            //             this.childTabClass = 'childTab2'
            //         } else if (scrollTop <= $idsTop[index][1]) {
            //             this.childTabClass = ''
            //         } else {
            //             this.childTabClass = 'childTab1'
            //         }
            //     }
            // })
        })
        this.screenWidth = document.documentElement.clientWidth - this.topHeight
        this.screenHeight = document.documentElement.clientHeight - this.topHeight
        window.addEventListener('resize', () => {
            this.screenWidth = document.documentElement.clientWidth - this.topHeight
            this.screenHeight = document.documentElement.clientHeight - this.topHeight
            $idsTop = arr.map(item => {
                let itemTop
                let arr
                if (item instanceof Array) {
                    const prevHeight = document.getElementById(
                        item[0]
                    ).offsetHeight //因这里一个选项有两个表格，需获取前一个表格的高度进行计算
                    arr = item.map((x, i) => {
                        if (i === 0) {
                            return document.getElementById(x).offsetTop
                        } else {
                            return (
                                document.getElementById(x).offsetTop +
                                prevHeight +
                                document.getElementById(item[0]).offsetTop
                            )
                        }
                    })
                    return arr
                } else {
                    itemTop = document.getElementById(item).offsetTop
                    return itemTop
                }
            })
        })
    }
}
</script>

<style lang="scss" scoped>
.lll {
    width: 100%;
    height: 30px;
    line-height: 30px;
    background: #f2f2f2;
    padding-right: 20px;
    padding-left: 20px;
}
.buttons {
    left: 0;
}
.e-form {
    margin-bottom: 80px;
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}

.e-table {
    background: #fff;
}
::v-deep.el-table .warning-row {
    display: none;
}
// ::v-deep.el-table__body-wrapper::-webkit-scrollbar{
//      width: 6px !important; // 横向滚动条
//     height: 10px !important// 纵向滚动条
// }

::v-deep .el-table__body-wrapper::-webkit-scrollbar {
    width: 6px; // 横向滚动条
    height: 10px; // 纵向滚动条
}
// 滚动条的滑块
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 5px;
}
::v-deep.el-table .warning-row {
    display: none;
}
.el-tab-pane {
    margin-left: -10px;
}
.childTab {
    ::v-deep .el-tabs__header {
        position: absolute !important;
    }
    ::v-deep .el-tabs__content {
        padding: 0 0 0 20px !important;
    }
}
.childTab1 {
    ::v-deep .el-tabs__header {
        position: absolute !important;
        .el-tabs__nav-scroll {
            position: relative;
            .el-tabs__nav {
                position: fixed;
                top: 0;
                width: 190px;
            }
        }
    }
}
.childTab2 {
    ::v-deep .el-tabs__header {
        position: absolute !important;
        .el-tabs__nav-scroll {
            position: relative;
            .el-tabs__nav {
                position: absolute;
                bottom: 0;
                width: 100%;
            }
        }
    }
}
::v-deep .el-table__fixed {
    height: 100% !important;
}
.tableHeadClass {
    ::v-deep .el-checkbox__inner {
        background: #2f62d7 !important;
    }
}
.cancelClass {
    ::v-deep .el-checkbox__inner {
        background: #fff !important;
    }
}
</style>
